// PanelDemo.java
// Using a JPanel to help lay out components.
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class PanelDemo extends JPanel {
private JButton buttons[];
public PanelDemo()
{
buttons = new JButton[ 5 ];
setLayout(new GridLayout( 1, buttons.length ) );
for ( int i = 0; i < buttons.length; i++ ) {
buttons[ i ] = new JButton( "Button " + (i + 1) );
add( buttons[ i ] );
}
}
public static void main( String args[] )
{
JFrame frame = new JFrame("Panel Demo");
JPanel panel = new PanelDemo();
Container c = frame.getContentPane();
c.add( panel, BorderLayout.SOUTH );
frame.setSize( 425, 150 );
frame.show();
frame.addWindowListener(
new WindowAdapter() {
public void windowClosing( WindowEvent e )
{
System.exit( 0 );
}
}
);
}
}
Maintained by John Loomis, last updated 15 June 2000