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

Answer:

The JTextField for Fahrenheit termperatue input.

Application with GUI

GUI of the application

Here is the program (not yet complete). It is based on the example in the previous chapter, so most of it should be understandable. Decide what belongs in the program then click on the button to see an anwser. Look at the picture as you decide in what order to add components.

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

public class FahrConvert extends  JFrame  implements  
{
  JLabel heading   = new JLabel("Convert Fahrenheit to Celsius");
  JLabel inLabel   = new JLabel("Fahrenheit    ");
  JLabel outLabel  = new JLabel("Celsius ");

  JTextField inFahr = new JTextField( 7 );
  JTextField outCel = new JTextField( 7 );

  int fahrTemp ;  // input  
  int celsTemp ;  // result 
  
  public FahrConvert()   // constructor 
  {  
     // choose the layout manager 
     setLayout( new  () ) ; 

     inFahr.addActionListener( this );
     
     add(   ) ;
     add(   ) ;
     
     add( outLabel );   
     add( inFahr );   
     add( outCel );   
     outCel.setEditable( ) ;
     
     setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );   
  }

   . . . . . . 

}

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

QUESTION 5:

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