// BorderLayoutDemo.java // Demos a BorderLayout with two panels // No functionality to the buttons // APPLET CODE="BorderLayoutDemo" HEIGHT=400 WIDTH=700 import java.awt.*; import javax.swing.*; public class BorderLayoutDemo extends JApplet { Container c; JPanel pNorth, pEast; String names[ ] = { "OK", "Cancel", "Re Do", "No Way", "Abort", "Retry", "Help", "Hey You", "Lehigh", "Matt", "Emily" }; JButton b[ ]; Font f; public void init( ) { c = getContentPane( ); c.setLayout( new BorderLayout( 10, 10 ) ); c.setBackground( Color.red ); // background of the content pane pNorth = new JPanel( ); pEast = new JPanel( ); b = new JButton[ names.length ]; f = new Font( "Arial", Font.BOLD, 96 ); // panel pNorth pNorth.setLayout( new GridLayout( 2, 2, 10, 10 ) ); for ( int i = 0; i < 4; i++ ) { b[ i ] = new JButton( names[ i ] ); pNorth.add( b[ i ] ); } pNorth.setBackground( Color.orange ); c.add( pNorth, BorderLayout.NORTH ); // panel pEast pEast.setLayout( new GridLayout( 3, 2, 10, 10 ) ); for ( int i = 4; i < 10; i++ ) { b[ i ] = new JButton( names[ i ] ); pEast.add( b[ i ] ); } pEast.setBackground( Color.cyan ); c.add( pEast, BorderLayout.EAST ); for ( int i = 8; i < 11; i++ ) b[ i ] = new JButton( names[ i ] ); c.add( b[ 8 ], BorderLayout.WEST ); c.add( b[ 9 ], BorderLayout.SOUTH ); b[ 10 ].setFont( f ); c.add( b[ 10 ], BorderLayout.CENTER ); } }