Which of the components will need to register a listener?

A good answer might be:

The "close-window" button of the frame and the TextField for fahrenheit termperatue input.

Application with GUI

Here is the program (not yet complete.) It is based on the previous example, so most of it should be understandable. Decide what belongs in the program for each button.

import java.awt.*; 
import java.awt.event.*;

public class fahrConvert
{ Label title = new Label("Convert Fahrenheit to Celsius"); Label inLabel = new Label("Enter Fahrenheit"); Label outLabel = new Label("Celsius ");
TextField inFahr =
TextField outCel = new TextField( 7 ); int fahrTemp ; // input from the user: fahrenheit temperature int celsTemp ; // result: celsius temperature fahrConvert() // constructor for fahrConvert {
setLayout( ) ; // choose the layout manager
inFahr.addActionListener( this );
add( ) ;
add( ) ;
add( outLabel ); add( inFahr ); add( outCel );
outCel.setEditable( ) ;
} public void convert( ) { celsTemp = ((fahrTemp-32) * 5) / 9; } public void actionPerformed( ActionEvent evt) { . . . . . . // more work is needed here repaint(); } public static void main ( String[] args ) { fahrConvert fahr = new fahrConvert() ; WindowQuitter wquit = new WindowQuitter(); fahr.addWindowListener( wquit ); fahr.setSize( 200, 150 ); fahr.setVisible( true ); } }
class WindowQuitter extends
{ public void windowClosing( WindowEvent e ) { System.exit( 0 ); } }

The GUI is nearly complete, but more work is needed:

  • There should be code to deal with the user's input.
  • The application needs to be called to process the data.
  • The result should be displayed.

QUESTION 5:

What method is used to get the text from the input TextField?

Click Here after you have answered the question