Java Genesis

Hints for Chapter 10: Graphical Components

Problem 1: hint 2

Here is the new constructor method for the class ToggleSquarePanel. The rest of the code for this class remains unchanged:
        public ToggleSquarePanel ( ) {
            setBackground(Color.yellow);
            addMouseListener(new MouseAdapter() {
                public void mouseEntered(MouseEvent evt) {
                        toggle();
                }
            });
        }
Now try to modify the SeekMousePanel class so that the circle jumps to the mouse's position when its button is pressed. Just as for the case above, we will need to change the method that is redefined in the anonymous inner class in the constructor method. In addition we will need to modify the seekMouse method.
 

Previous Hint | Next Hint