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.*;
{
Label title = new Label("Convert Fahrenheit to Celsius");
Label inLabel = new Label("Enter Fahrenheit");
Label outLabel = new Label("Celsius ");
TextField outCel = new TextField( 7 );
int fahrTemp ; // input from the user: fahrenheit temperature
int celsTemp ; // result: celsius temperature
fahrConvert() // constructor for fahrConvert
{
inFahr.addActionListener( this );
add( outLabel );
add( inFahr );
add( outCel );
}
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 );
}
}
{
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.
|