HelloAWT.java - My First AWT Program

This section provides a tutorial example on how to write a simple Java AWT program. HelloAWT.java is my first AWT program that displays a blank window with 'Hello world!' in the window title bar.



Below is my first AWT program, HelloAWT.java:

import java.awt.Frame;
public class HelloAWT {
   public static void main(String[] a) {
      Frame f = new Frame("Hello world!");
      f.setVisible(true);
   }
}

If you have JDK installed on your system, you can compile and run this program in a command window:

C:herong>javac HelloAWT.java
C:herong>java HelloAWT

Once the program is running, you will see a small new window showing up on your screen. If use the mouse pointer to drag its edges to make it larger, you can see the hello text in the title area as shown in this picture:

First AWT - Hello World!
First AWT - Hello World!

The new window will stay on your screen until you press Ctrl-C in the command window to terminate the running program.



 

Table of Contents

 About This Book

 JDK (Java Development Kit)

 Introduction of Java Swing Package

 Graphics Environment of the Local System

 JFrame - Main Frame Class

 JLabel - Swing Label Class

 JButton - Swing Button Class

 JCheckBox - Swing Check Box Class

 JRadioButton - Swing Radio Button Class

 JTextField - Swing Text Field Class

 JComboBox - Swing Combo Box Class

 Menu Bar, Menus, Menu Items and Listeners

 Creating Internal Frames inside the Main Frame

 Layout of Components in a Container

 LookAndFeel and UIManager

 Option Dialog Boxes

 JEditorPane - The Editor Pane Class

 SwingWorker - The Background Task Worker

AWT (Abstract Windows Toolkit)

 What Is AWT (Abstract Windows Toolkit)

HelloAWT.java - My First AWT Program

 Closing AWT Frame and Terminating Application

 Drawing Graphics - Using paint() on Frame or Component

 Creating Labels with java.awt.Label Class

 Creating Buttons with java.awt.Button Class

 AWT Button Action Handler at the Component Level

 AWT Button Action Handler at the Frame Level

 AWT Button Mouse Click Handler at the Frame Level

 AWT TextField and ActionListener

 MenuBarTest.java - AWT Menu Bar Test Program

 MenuTest.java - AWT Menu Test Program

 MenuItemTest.java - AWT Menu Item Test Program

 MenuItemActionListenerTest.java - AWT Menu Item Action Listener

 Integration with Desktop System

 Outdated Tutorials

 References

 Full Version in PDF/EPUB