package Lect39GUIs; import java.awt.*; import javax.swing.*; import javax.swing.border.*; public class SwingExampleAutoLayout { private final static int WIDTH = 500, HEIGHT = 400; public SwingExampleAutoLayout() { JFrame frame = buildFrame(); buildGUI(frame); displayFrame(frame); } public JFrame buildFrame() { try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } catch (Exception e) {} // Create a top-level window to put the picture in JFrame frame; frame = new JFrame("Swing Example"); frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); return frame; } public void buildGUI(JFrame frame) { JPanel panel = new JPanel(); panel.setPreferredSize(new Dimension(WIDTH, HEIGHT)); panel.setBackground(Color.WHITE); panel.setLayout(new BorderLayout()); JButton button = new JButton("Do it"); panel.add(button, BorderLayout.NORTH); JLabel label = new JLabel(); panel.add(label, BorderLayout.SOUTH); JTextArea textArea = new JTextArea(); textArea.setLineWrap(true); textArea.setBorder(new EtchedBorder()); panel.add(textArea, BorderLayout.CENTER); button.addActionListener(new DoIt(label)); frame.setContentPane(panel); } public void displayFrame(JFrame frame) { frame.setLocation(100, 100); frame.pack(); frame.show(); } static public void main(String[] args) { new SwingExampleAutoLayout(); } }