A good answer might be:

The complete application (suitable for copying and running) is below:

An Application You Can Run

Of course, you will want to copy the following into NotePad, save it to a file, compile and run it.

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

public class fahrConvert extends Frame implements ActionListener
{
  Label title    = new Label("Convert Fahrenheit to Celsius");
  Label inLabel  = new Label("Enter Fahrenheit");
  Label outLabel = new Label("Celsius ");

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

  int fahrTemp ;
  int celsTemp ;
  
  fahrConvert()                           // constructor for fahrConvert
  {  
     setLayout( new FlowLayout() );       // choose the layout manager 

     inFahr.addActionListener( this );
     add( title );                      
     add( inLabel );                      
     add( outLabel );                      
     add( inFahr );                      
     add( outCel );                      
     outCel.setEditable( false );
  }

  public void convert( )  
  {
    celsTemp = ((fahrTemp-32) * 5) / 9;
  }

  public void actionPerformed( ActionEvent evt)  
  {
    String userIn = inFahr.getText() ;
    fahrTemp = Integer.parseInt( userIn ) ;

    convert() ;

    outCel.setText( celsTemp+" " );
    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 WindowAdapter 
{
  public void windowClosing( WindowEvent e )
  {
    System.exit( 0 );  // what to do for this event--exit the program
  }
}

QUESTION 7:

  • If the results are incorrect, which part do you debug? The GUI code or the application code?
  • If the graphics are incorrect, which part do you debug? The GUI code or the application code?

Click Here after you have answered the question