go to previous page   go to home page   go to next page

Answer:

  1. How many frames are there?
    • Just one.
  2. What GUI components will it contain?
    • The "Red" button and the "Green" button.
  3. What objects generate events?
    • Both buttons.
  4. What objects receive events?
    • A listener for button events, the frame that contains the buttons.

Actually, there are many events the GUI may generate, but other than button clicks, most of those events are ignored. There are other events, such as clicking on the close icon of the frame, that are not ignored, but are handled by the frame.


The Frame

You might have answered that each button needs its own listener. That would work, but we can use just one listener. First write a class definition for the container frame. Here is a skeleton:

import java.awt.*; 
import java.awt..*;
import javax.swing.*; 

public class TwoButtons extends   implements  
{


  . . . . more code will go here . . . . 

  public static void main ( String[] args )
  {
    TwoButtons demo  = new new TwoButtons( "Click a Button" ) ;
    
    demo.( 200, 150 );     
    demo.setVisible( true );      

  }
}

Notice that this program includes main() inside the TwoButtons class.

For now, decide what class to extend and what interface to implement.


QUESTION 4:

Fill in the blanks.