A good answer might be:

Remember that with FlowLayout you need to add components in raster order.

Near-complete GUI

Here is the program so far:

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

public class percentFat extends Frame implements ActionListener
{
  Label title     = new Label("Percent of Calories from Fat");
  Label fatLabel  = new Label("Enter grams of fat:   ");
  Label calLabel  = new Label("Enter total calories: ");
  Label perLabel  = new Label("Percent calories from fat: ");

  TextField inFat  = new TextField( 7 );
  TextField inCal  = new TextField( 7 );
  TextField outPer = new TextField( 7 );

  Button    doit   = new Button("Do It!");

  int calories ;          // input from the user: total calories per serving
  int fatGrams ;          // input from the user: grams of fat per serving
  double percent ;        // result: percent of calories from fat
    
  percentFat()            // constructor  
  {  
    setLayout( new FlowLayout() );       // choose the layout manager 

    add( title );                      
    add( fatLabel );                      
    add( inFat );                      
    add( calLabel );                      
    add( inCal );
    add( perLabel );
    add( outPer );                      
    outPer.setEditable( false );

    add( doit );     
    doit.addActionListener( this );
  }

  . . . . .

QUESTION 14:

Why did we not use setActionCommand() with the doit Button?

Click Here after you have answered the question