Below simple image shows a GUI application for adding two numbers and then showing their result.
Java supports this kind of software with Swing and Abstract Windowing Toolkit, a collection of Java classes that represent all the different buttons, text fields, sliders, and other components that can be part of a GUI, as well as the classes needed to take user input from those components.
Swing includes everything you need to write programs that use a GUI. With Java’s user interface classes, you can create a GUI that includes all the following and more:
Buttons, check boxes, labels, and other simple components .
Text fields, sliders, and other more complex components .
Pull-down menus and pop-up menus .
Windows, frames, dialog boxes, panels, and applet windows
GUI Applications in JAVA Can be built using JFC and Swing and JAVAFX
1. JFC and SWING GUI Applications
JFC is short for Java Foundation Classes, which encompass a group of features for building graphical user interfaces (GUIs) and adding rich graphics functionality and interactivity to Java applications. It is defined as containing the features shown in the table below.
Feature | Description |
---|---|
Swing GUI Components | Includes everything from buttons to split panes to tables. Many components are capable of sorting, printing, and drag and drop, to name a few of the supported features. |
Pluggable Look-and-Feel Support | The look and feel of Swing applications is pluggable, allowing a choice of look and feel. For example, the same program can use either the Java or the Windows look and feel. Additionally, the Java platform supports the GTK+ look and feel, which makes hundreds of existing look and feels available to Swing programs. Many more look-and-feel packages are available from various sources. |
Accessibility API | Enables assistive technologies, such as screen readers and Braille displays, to get information from the user interface. |
Java 2D API | Enables developers to easily incorporate high-quality 2D graphics, text, and images in applications and applets. Java 2D includes extensive APIs for generating and sending high-quality output to printing devices. |
Internationalization | Allows developers to build applications that can interact with users worldwide in their own languages and cultural conventions. With the input method framework developers can build applications that accept text in languages that use thousands of different characters, such as Japanese, Chinese, or Korean. |
This trail concentrates on the Swing components. We help you choose the appropriate components for your GUI, tell you how to use them, and give you the background information you need to use them effectively. We also discuss other features as they apply to Swing components.
Which Swing Packages Should I Use?
The Swing API is powerful, flexible — and immense. The Swing API has 18 public packages:
javax.accessibility | javax.swing.plaf | javax.swing.text |
javax.swing | javax.swing.plaf.basic | javax.swing.text.html |
javax.swing.border | javax.swing.plaf.metal | javax.swing.text.html.parser |
javax.swing.colorchooser | javax.swing.plaf.multi | javax.swing.text.rtf |
javax.swing.event | javax.swing.plaf.synth | javax.swing.tree |
javax.swing.filechooser | javax.swing.table | javax.swing.undo |
Fortunately, most programs use only a small subset of the API. This trail sorts out the API for you, giving you examples of common code and pointing you to methods and classes you're likely to need. Most of the code in this trail uses only one or two Swing packages:
javax.swing
javax.swing.event (not always required)
2. JAVAFX GUI Applications
JavaFX is a set of graphics and media packages that enables developers to design, create, test, debug, and deploy rich client applications that operate consistently across diverse platforms.
Since the JavaFX library is written as a Java API, JavaFX application code can reference APIs from any Java library. For example, JavaFX applications can use Java API libraries to access native system capabilities and connect to server-based middleware applications.
The look and feel of JavaFX applications can be customized. Cascading Style Sheets (CSS) separate appearance and style from implementation so that developers can concentrate on coding. Graphic designers can easily customize the appearance and style of the application through the CSS. If you have a web design background, or if you would like to separate the user interface (UI) and the back-end logic, then you can develop the presentation aspects of the UI in the FXML scripting language and use Java code for the application logic. If you prefer to design UIs without writing code, then use JavaFX Scene Builder. As you design the UI, Scene Builder creates FXML markup that can be ported to an Integrated Development Environment (IDE) so that developers can add the business logic.
With JavaFX, you can build many types of applications. Typically, they are network-aware applications that are deployed across multiple platforms and display information in a high-performance modern user interface that features audio, video, graphics, and animation.
In the next sections we will start to build a simple GUI application in JAVA using Swing.
Swing package is built on top of Abstract Windows Toolskit.