/* GUI07.java CIS 160 David Klick 2011-09-24 Formatting labels, adding textboxes */ import java.awt.Container; import java.awt.GridLayout; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JTextField; import javax.swing.SwingUtilities; public class GUI07 extends JFrame { public GUI07() { SwingUtilities.invokeLater(new Runnable() { public void run() { createAndShowGUI(); } }); } private void createAndShowGUI() { // set title, size, and close operation setSize(300, 200); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // create components JLabel lblLength = new JLabel("Length:", JLabel.RIGHT); JLabel lblWidth = new JLabel("Width:", JLabel.RIGHT); JTextField txtArea = new JTextField(20); JTextField txtPerim = new JTextField("perimeter", 20); // add components to this frame's content pane Container c = getContentPane(); c.setLayout(new GridLayout(2, 2)); // rows, columns c.add(lblLength); c.add(txtArea); c.add(lblWidth); c.add(txtPerim); setVisible(true); } public static void main(String[] args) { GUI07 app = new GUI07(); } }