Is there a paint() method for this buttonDemo frame?

A good answer might be:

Yes---the standard paint() method inherited from the parent class, Frame. Since nothing special needs to be done, the inherited paint() works fine. Remember that it will automatically paint the frame and all the GUI components it contains.

Program's Output

paint() is called when the Java system knows that it must repaint the screen. It knows this when any of several things has happened:

  • The frame has just been created.
  • The frame has been maximized.
  • The frame was previously hidden behind another frame and has just been exponsed.
However, a mere button click does not necessarily mean that a frame should be repainted. If it does (as it does in this program) then repaint() should be called in the actionPerformed() method.

Here is the output of the program. The original frame is on the left. On the right is the frame after the button has been clicked. Clicking on the frame's "close window" button closes the frame.

After the button is clicked once, futher clicking has no visible effect. Although the events are handled, all that happens is that the frame is set to blue each time.

The button in the frame generates ActionEvents. The "close window" button (and the other two little buttons next to it) generate window events. You can't use the ActionListener interface for them. Sometimes the little buttons are called "icons" to make them distinct from class Button, who's objects are explicitly added to a container.

QUESTION 11:

(Memory Test: ) What is the name of the method that receives ActionEvents when a Button is clicked?

Click Here after you have answered the question