Java Genesis

Hints for Chapter 9: Graphics and Event Handling

Problem 9: toggling the square

Consider first the problem of toggling the square between red and blue. What we can do is in the class ToggleSquarePanel replace the instance variable declaration

	private boolean filled = true;
by the declaration
        private Color colour = Color.red;
We now need to modify the paintComponent method and in the anonymous inner class the mousePressed method.

Try this before looking at the next hint.


Next Hint