public class PanelFrame extends JFrame
1: // Fig. 11.43: PanelFrame.java
2: // Using a JPanel to help lay out components.
3: import java.awt.GridLayout;
4: import java.awt.BorderLayout;
5: import javax.swing.JFrame;
6: import javax.swing.JPanel;
7: import javax.swing.JButton;
8:
9: public class PanelFrame extends JFrame
10: {
11: private JPanel buttonJPanel; // panel to hold buttons
12: private JButton buttons[]; // array of buttons
13:
14: // no-argument constructor
15: public PanelFrame()
16: {
17: super( "Panel Demo" );
18: buttons = new JButton[ 5 ]; // create buttons array
19: buttonJPanel = new JPanel(); // set up panel
20: buttonJPanel.setLayout( new GridLayout( 1, buttons.length ) );
21:
22: // create and add buttons
23: for ( int count = 0; count < buttons.length; count++ )
24: {
25: buttons[ count ] = new JButton( "Button " + ( count + 1 ) );
26: buttonJPanel.add( buttons[ count ] ); // add button to panel
27: } // end for
28:
29: add( buttonJPanel, BorderLayout.SOUTH ); // add panel to JFrame
30: } // end PanelFrame constructor
31: } // end class PanelFrame
32:
33:
34: /**************************************************************************
35: * (C) Copyright 1992-2005 by Deitel & Associates, Inc. and *
36: * Pearson Education, Inc. All Rights Reserved. *
37: * *
38: * DISCLAIMER: The authors and publisher of this book have used their *
39: * best efforts in preparing the book. These efforts include the *
40: * development, research, and testing of the theories and programs *
41: * to determine their effectiveness. The authors and publisher make *
42: * no warranty of any kind, expressed or implied, with regard to these *
43: * programs or to the documentation contained in these books. The authors *
44: * and publisher shall not be liable in any event for incidental or *
45: * consequential damages in connection with, or arising out of, the *
46: * furnishing, performance, or use of these programs. *
47: *************************************************************************/