JFrame Example

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 myFrame = new JFrame("My JFrame");
    myFrame.setSize(250, 250);
    myFrame.setLocation(300,200);
    myFrame.getContentPane().add("Center", new JTextArea(10, 40));
    myFrame.show();
    
  }
  
}

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 closeable by default whereas AWT frames are not.


Previous | Next | Top
Last Modified December 15, 1999
Copyright 1997-1999 Elliotte Rusty Harold
elharo@metalab.unc.edu