Adding Panels to the Frame
If you forget to add a Panel (or other component) to the frame,
then those components will not appear on the monitor screen.
Its easy to forget to do this.
Here is the program fragment, so far:
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 fatPanel = new Panel(); // fat input components
Panel calPanel = new Panel(); // calorie input components
Panel perPanel = new Panel(); // percent fat output components
percentFat() // constructor
{
setTitle("Calories from Fat");
setLayout( new FlowLayout() ); // choose the layout manager
fatPanel.add( fatLabel );
fatPanel.add( inFat );
calPanel.add( calLabel );
calPanel.add( inCal );
perPanel.add( perLabel );
perPanel.add( outPer);
outPer.setEditable( false );
doit.addActionListener( this );
}
|
There are five components: the title, the doit button, and the
three panels.
So the add() method is used five times.
Look back at how the
fat application
GUI looks to decide what the order should be.
|