|
Swing
This chapter discusses:
- What is Swing.
- My first Swing program.
What Is Swing?
Swing: A Java package name, javax.swing, in J2SDK
(Java 2 Software Development Kit). It provides many enhancements to the
existing graphics package, AWT (Abstract Windows Toolkit) package, java.awt.
javax.swing and java.awt together offer a complete API (Application
Programming Interface) for Java applications to operate graphical devices and create
GUI (Graphical User Interfaces).
SwingHello.java - My First Swing Program
Below is my first Swing program, SingHello.java:
import javax.swing.*;
public class SwingHello {
public static void main(String[] a) {
JFrame f = new JFrame("Hello world!");
f.setVisible(true);
}
}
If you have JDK installed on your system, you can compile and run this program
in a command window:
javac SwingHello.java
java -cp . SwingHello
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.
The new window will stay on your screen until you press Ctrl-C in the launching window
to terminate the running program.
If you don't have JDK installed on your system, you can read my other book, "Herong's
Notes on Java", for installation information.
|