JFrame frame = new JFrame();
frame.pack();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
JButton helloButton = new JButton("Say Hello");
Container contentPane = frame.getContentPane();
container.setLayout(new FlowLayout());
contentPane.add(helloButton);

The buttons do not work yet!
FrameTest.javaimport java.awt.*;
import javax.swing.*;
public class FrameTest
{
public static void main(String[] args)
{
JFrame frame = new JFrame();
JButton helloButton = new JButton("Say Hello");
JButton goodbyeButton = new JButton("Say Goodbye");
final int FIELD_WIDTH = 20;
JTextField textField = new JTextField(FIELD_WIDTH);
textField.setText("Click a button!");
Container contentPane = frame.getContentPane();
contentPane.setLayout(new FlowLayout());
contentPane.add(helloButton);
contentPane.add(goodbyeButton);
contentPane.add(textField);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.pack();
frame.setVisible(true);
}
}
Maintained by John Loomis, updated Fri Feb 23 18:02:37 2007