New Panels
Here is part of the new, improved program.
Notice that it has two more Panels than before.
Each new Panel will need a component added to it.
You will also have to set the layout manager correctly.
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");
fatPanel.add( fatLabel );
fatPanel.add( inFat );
calPanel.add( calLabel );
calPanel.add( inCal );
perPanel.add( perLabel );
perPanel.add( outPer);
. . . . . . .
}
|
|