1. Technology

Create a Simple Window Using JFrame

By

1 of 7

Reference the Graphical Components
Import Java Classes

Microsoft product screen shot(s) reprinted with permission from Microsoft Corporation.

A graphical user interface has to start with a top-level container. It provides a home for the other components of the interface, and dictates the overall feel of the application. In this tutorial, you will be introduced to the JFrame class. It will be used to create a simple top-level window for a Java application.

Open your editor to start a new text file, and type in the following:

 import java.awt.*;
 import javax.swing.*; 

Java comes with a set of code libraries that are designed to help programmers. They provide access to classes that perform specific functions, to save you the bother of having to write them yourself. The two import statements above, let the compiler know that the application wants to use some of the pre-built functionality contained within the "AWT" and "Swing" code libraries.

AWT stands for “Abstract Window Toolkit”. It contains classes that programmers can use to make graphical components, e.g., buttons, labels, frames. Swing is built on top of AWT, and provides a new set of more sophisticated graphical interface components. With just two lines of code, we gain access to these graphical components, and can use them in the Java application.

  1. About.com
  2. Technology
  3. Java
  4. Create User Interfaces
  5. Create a Simple Window Using JFrame

©2014 About.com. All rights reserved.