/* GUI06.java CIS 160 David Klick 2011-09-24 Creating and adding components using a layout manager */ import java.awt.Container; import java.awt.GridLayout; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.SwingUtilities; public class GUI06 extends JFrame { public GUI06() { SwingUtilities.invokeLater(new Runnable() { public void run() { createAndShowGUI(); } }); } private void createAndShowGUI() { // set title, size, and close operation setTitle("With Layout Manager"); setSize(300, 200); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // create components JLabel lblLength = new JLabel("Length:"); JLabel lblWidth = new JLabel("Width:"); // add components to this frame's content pane Container c = getContentPane(); c.setLayout(new GridLayout(2, 1)); // rows, columns c.add(lblLength); c.add(lblWidth); setVisible(true); } public static void main(String[] args) { GUI06 app = new GUI06(); } }