When adding these Panels, why can we say just "add" without using dot notation (as was needed in the previous group of statements)?

A good answer might be:

These statements lie within the constructor for the class percentFat. This class "isa" Frame, so we are using its add() method. When we added components to the Panels, we needed to use the Panels' add() method.

Complete Application

Here is the complete application. Notice that most of the program has not changed from before.

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!");

  Panel ttlPanel   = new Panel();   // title 
  Panel fatPanel   = new Panel();   // fat input components
  Panel calPanel   = new Panel();   // calorie input components
  Panel perPanel   = new Panel();   // percent fat output components
  Panel butPanel   = new Panel();   // do it button

  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
  {  
    setTitle("Calories from Fat");
    setLayout( new GridLayout(5, 1) );       // choose the layout manager 

    ttlPanel.add( title );
    fatPanel.add( fatLabel );
    fatPanel.add( inFat );
    calPanel.add( calLabel );
    calPanel.add( inCal );
    perPanel.add( perLabel );
    perPanel.add( outPer);
    butPanel.add( doit );

    add( ttlPanel );                      
    add( fatPanel );                      
    add( calPanel );                      
    add( perPanel );                      
    outPer.setEditable( false );

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

  }

  // The application
  public void calcPercent( )  
  {
    percent = ( (fatGrams * 9.0) / calories ) * 100.0 ;
  }

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

    userIn    = inCal.getText()  ;
    calories  = Integer.parseInt( userIn ) ;

    calcPercent() ;

    outPer.setText( percent+" " );
    repaint();                  
  }

   
  public static void main ( String[] args )
  {
    percentFat fatApp  = new percentFat() ;

    WindowQuitter wquit = new WindowQuitter(); 
    fatApp.addWindowListener( wquit );
    
    fatApp.setSize( 280, 200 );
    fatApp.setResizable( true );
    fatApp.setVisible( true );      
    
  }
}

class  WindowQuitter  extends WindowAdapter 
{
  public void windowClosing( WindowEvent e )
  {
    System.exit( 0 );   
  }
}

QUESTION 15:

Has the event handling part of the program been affected by the new Panels?

Click Here after you have answered the question