public class percentFatPan extends JFrame
implements ActionListener
{
public percentFatPanel()
{
getContentPane().setLayout(
new BoxLayout( getContentPane(), BoxLayout.Y_AXIS );
. . . . .
Notice how two uses of getContentPane() are needed to set
the layout manager.
The second is needed as a parameter for the BoxLayout
constructor.
Now add the top label, the panels, and the button to the
content pane:
JLabel title = new JLabel("Percent of Calories from Fat");
JLabel fatLabel = new JLabel("Enter grams of fat: ");
JLabel calLabel = new JLabel("Enter total calories: ");
JLabel perLabel = new JLabel("Percent calories from fat: ");
JTextField inFat = new JTextField( 7 );
JTextField inCal = new JTextField( 7 );
JTextField outPer = new JTextField( 7 );
JButton doit = new JButton("Do It!");
JPanel fatPanel = new JPanel();
JPanel calPanel = new JPanel();
JPanel perPanel = new JPanel();
public percentFatPanel()
{
fatPanel.add( fatLabel );
fatPanel.add( inFat );
calPanel.add( calLabel );
calPanel.add( inCal );
perPanel.add( perLabel );
perPanel.add( outPer );
getContentPane().setLayout(
new BoxLayout( getContentPane(), BoxLayout.Y_AXIS );
getContentPane().add( );
getContentPane().add( );
getContentPane().add( );
getContentPane().add( );
getContentPane().add( );