13.7 Avoiding Errors and Debugging
Avoiding Errors
- If you change the contents of a window, be sure to redraw it. To
do so, call the repaint method, not the paint method. If you call
repaint, the window manager will automatically call paint at an
appropriate time.
- In implementing an interface, be sure to include all required methods
with exactly the right parameters. If anything is missing or wrong,
the compiler will complain.
Debugging
- If a component is not responding as it should, check that you have
registered the component as a listener to the appropriate action. For
example, if a button is not responding to mouse clicks, check to see if
you have implemented the ActionListener interface for that button
object. If the component is not registered as a listener, then its
actionPerformed method will not be executed.