Home

A Few Things about Java GUIs

|
|  Updated:  
2017-10-13 12:44:18
Java and XML For Dummies
Explore Book
Buy On Amazon
Before you jump into Java GUIs, there are a few things you should know. Java comes with three sets of classes for creating GUI applications:
  • The Abstract Window Toolkit (AWT): The original set of classes, dating back to JDK 1.0.

Classes in this set belong to packages whose names begin with java.awt. Components in this set have names like Button, TextField, Frame, and so on.

Each component in an AWT program has a peer — a companion component that belongs to the computer's own operating system. For example, when you create an AWT Button, a Mac computer creates its own kind of button to be displayed on the user's screen. When the same program runs on a Windows computer, the Windows computer creates a different kind of button (a Windows button) to display on the computer's screen. The Java code in the AWT interacts with the Mac or Windows button, adding additional functionality where functionality is needed.

The AWT implements only the kinds of components that were available on all common operating systems in the mid-1990s. So, using AWT, you can add a button to your application, but you can't easily add a table or a tree.

  • Java Swing: A set of classes created to fix some of the difficulties posed by the use of the AWT. Swing was introduced in J2SE 1.2.

Classes in this set belong to packages whose names begin with javax.swing. Components in this set have names like JButton, JTextField, JFrame, and so on.

Unlike an old AWT component, a Swing component has no peer. When you create a JButton in your Java program, the computer's operating system doesn't create a button of its own. Instead, the JButton that you see is a pure Java object. Java's visual rendering code draws this object on a window. This is both good news and bad news. The good news is, a Swing program looks the same on every operating system. In a Swing program, you can create table components and tree components because Java simply draws them in the computer's window. The bad news is, Swing components aren't pretty. A JButton looks primitive and crude compared to a Mac button or a Windows button.

Java's Swing classes replace some (but not all) of the classes in the older AWT. To use some of the Swing classes, you have to call on some of the old AWT classes.

  • JavaFX: The newest set of GUI classes in Oracle standard Java. JavaFX comes with new(er) versions of Java 7 and with all later versions of Java.

Classes in this set belong to packages whose names begin with javafx.

JavaFX supports over 60 kinds of components. (Sure, you want a Button component. But do you also want an Accordion component? JavaFX has one.) In addition, JavaFX supports multitouch operations and takes advantage of each processor's specialized graphics capabilities.

About This Article

This article is from the book: 

About the book author: