import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.border.*; /** * playing lightly with BorderLayout * * @author Sharon Tuttle * @version 2015-09-29 */ public class BorderLayoutPlay { /** * creates a frame for BorderLayout play * * @param args not used here */ public static void main(String[] args) { EventQueue.invokeLater( new Runnable() { public void run() { BorderLayoutPlayFrame aFrame = new BorderLayoutPlayFrame(); aFrame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE); aFrame.setVisible(true); } }); } } /** * a frame with some BorderLayout play */ class BorderLayoutPlayFrame extends JFrame { public static final int DEFAULT_WIDTH = 500; public static final int DEFAULT_HEIGHT = 350; /** * construct a BorderLayoutPlay-panel frame instance */ public BorderLayoutPlayFrame() { this.setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT); this.setTitle("BorderLayout Playing"); // create and add a BorderLayoutPlay panel to my frame BorderLayoutPlayPanel aBorderLayoutPlayPanel = new BorderLayoutPlayPanel(); this.add(aBorderLayoutPlayPanel); } } /** * a panel with BorderLayout playing */ class BorderLayoutPlayPanel extends JPanel { // named constants for bigger fonts private final static Font DISPLAY_FONT = new Font("Dialog", Font.PLAIN, 20); private final static Font HUGE_FONT = new Font("Dialog", Font.PLAIN, 60); /** * construct a panel to play with BorderLayout */ public BorderLayoutPlayPanel() { /* make this new panel use BorderLayout */ this.setLayout(new BorderLayout()); /* now, create and add some components */ JButton southBtn = new JButton("SOUTH!"); southBtn.setFont(HUGE_FONT); this.add(southBtn, BorderLayout.SOUTH); JButton eastBtn = new JButton("EAST!"); eastBtn.setFont(HUGE_FONT); this.add(eastBtn, BorderLayout.EAST); JButton westBtn = new JButton("WEST!"); westBtn.setFont(HUGE_FONT); this.add(westBtn, BorderLayout.WEST); JButton centerBtn = new JButton("CENTER!"); centerBtn.setFont(HUGE_FONT); this.add(centerBtn, BorderLayout.CENTER); JButton northBtn = new JButton("NORTH!"); //northBtn.setFont(HUGE_FONT); this.add(northBtn, BorderLayout.NORTH); // comment out the statements above, and uncomment the statements // below, to try out the clicker question // /* this.add(new Button("Looky")); this.add(new Button("Eep"), BorderLayout.SOUTH); this.add(new Button("Huh")); */ } }