What follows is a very simple program that puts up a window. You
can move the window and resize it. The window has a single
JTextArea
component that lets you edit some text.
import javax.swing.*;
public class JFrameTester {
public static void main(String[] args) {
JFrame f = new JFrame("A JFrame");
f.setSize(250, 250);
f.setLocation(300,200);
f.getContentPane().add(BorderLayout.CENTER, new JTextArea(10, 40));
f.setVisible(true);
}
}
JFrames (and Swing containers in general) differ from AWT frames (and AWT containers in general) in that you must add component's to the JFrame's content pane rather than directly to the frame itself. Furthermore JFrames are closable by default whereas AWT frames are not.