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

Answer:

Repeater

The labels do not need listeners because they generate no actions. The bottom text field does not need a listener because it will have its text set by the program (this is not an event.) Here is the application. Decide what should go in place of the ten buttons:

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

public class Repeater extends JFrame implements ActionListener
{

   JLabel inLabel     = new  (" " ) ;
   JTextField inText  = new JTextField( 15 );

   JLabel outLabel     = new  (" " ) ;
   JTextField outText = new JTextField( 15 );
   
   Repeater( String title )  // constructor
   {  
      super( title );
      setLayout( new FlowLayout() );        
      add(   ) 
      add(   ) ;
      add(   ) ;
      add(   ) ;

      inText.addActionListener( ) ;
      setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );   
   }

  public void actionPerformed( ActionEvent evt)  
  {
    String name = inText.getText();
    outText.( name );
    repaint();                  
  }

  public static void main ( String[] args )
  {
    . . . . . .
  }
}

In this program, the labels and text fields are constructed in the declartions outside of the constructor for the Repeater class. (In previous programs, componenents were constructed inside the frame's constructor.) Both styles work fine.

QUESTION 10:

Decide what should go in each blank. Fill in the blanks by clicking on a button.