Saturday, May 21, 2022

The java desktop module

The java desktop module is the modern evolution of the abstract window toolkit (AWT) released with the first version of Java. With the modularization of the JDK, all the functionality that grew around AWT was moved into the desktop module. The module has four major components:
  • AWT
  • Swing
  • Java 2D
  • The Java Sound API
Aside from these components, there are several minor components like accessibility, drag and drop, and java beans. Conceptually, the AWT can be be broken down in to two components: the user interface component and the media subsystem. The UI framework evolved into Swing and the media subsystem evolved into Java 2D and eventually Java Sound.

The basic media functionality that a program for desktop computers needs to support are 2D graphics and sound. These are the basic building blocks of all media applications. These are provided by the 2D graphics API and the sound API. However, media applications don't include interactivity which is the role of the user interface framework.

In order to support interactive applications Java SE desktop applications use the Java 1.1 event model. In this model, applications add one more listeners to the events to a given component. As Swing is built on the building blocks of AWT, it uses the same java.awt.event event model as AWT. By combining rich graphics built with the Java 2D API and the event model, any kind of interactive GUI program can be built with Java.

AWT

The AWT was the first widget toolkit released for Java. The main role of AWT now is to be a building block for Swing. The main way that AWT does this is through the Component and Container classes which all Swing components extend from. The Component and Container class provide a couple hundred methods dealing with a wide variety of purposes like event handling, grouping and layout, resizing, colouring, painting, fonts, and so on.

The Component class defines the interface from widgets to the AWT event model, which is also still used by Swing. Container describes the interface to the AWT layout managers, which again are reused with Swing. Aside from the Component and Container classes, the various Window classes of AWT are inherited by Swing. A JFrame for example extends from the AWT classes Frame and Window.

Swing

If you want to actually build a graphical user interface application using Java SE, you are going to be using Swing. It builds upon AWT, but it provides a wide variety of original functionality and many new widgets. Swing components include labels, button, checkboxes, lists, menus, radio buttons, sliders, spinners, text fields, text areas, editor panes, progress bars, trees, tables, and color panes among others.

Swing is also notable by the fact that you can use HTML and CSS in Swing components. Just include a well formed HTML document in your JLabels. This certainly comes in handy when you want to quickly add rich text to Swing programs. Swing also comes with its own pluggable look and feel framework, so that you can change how Swing components look.

Java 2D

The Java 2D API includes all kinds of functionality to support 2D graphics on the Java platform: including all the support for colors, fonts, geometry, graphics, painting, imaging, and printing. The Java 2D API is the natural evolution of the drawing part of the AWT toolkit.

With the 2D graphics API, you can create all kinds of shapes using the java.awt.geom package and the Shape interface. Then you can control the drawing of them, with colors, compositing, rendering hints, etc. The 2D graphics API also can easily be used functionally from Clojure to create all kinds of amazing visualisations, which I will talk about later.

The Java sound API

The Java 1.3 release introduced the Java sound API, which later became a part of the desktop module. It lets you add the one final piece to the desktop application programming puzzle, which is sound. The sound API only supports three file formats: AU, AIFF, and WAV. Therefore, to handle other file formats you may need other libraries.

The Java sound API also includes support for the synthesis of MIDI music file formats like MIDI type 0, MIDI type 1, and the Rich Music Format (RMF). It enables the sequencing and synthesis of MIDI wavelets and access to MIDI hardware devices. So it adds the finishing touchs to the desktop module.

External links:
The java desktop module

No comments:

Post a Comment