Java GUI’s Using the Swing API 1

What are the Java Foundation Classes (JFC)?

  • JFC, or Java Foundation Classes, is a set of Graphical User Interface (GUI) support packages that are available as part of the java SE platform and which became core application program interfaces (APIs) in JDK 1.2.
  • As a result of this, some of the boundaries between JFC and core JDK have become blurred, but in this, JFC includes the following features:
    • The Swing component set: – The Swing is an enhanced component set that provides replacement components for those in the original AWT and a number of more advanced components.
    • 2D graphics: – Using the Java 2D API, you can perform advanced drawing, complex color manipulations, shape and transformation (rotate, shear, stretch, and so forth) handling, and treat text as shapes that can be manipulated.
    • Pluggable look-and-feel: – This feature provides Swing components a choice of look-and-feel. The same program can be rendered in Microsoft Windows, Motif, and Metal look-and-feel formats.
    • Accessibility: – national governments are increasingly mandating that computer programs used in their departments are accessible to those with disabilities. The Swing component set facilities such programming by means of the accessibility APIs. It does provide interfaces for associative technologies, such as screen readers, Screen magnifiers, audible text readers (speech processing), and so on.
    • Drag and Drop: – GUI based data transfer, both between the elements of one program and between the different programs, has been a feature of the modern GUI systems for a number of years. This type of transfer falls into two forms from the user’s point of view. These are cut and paste and drag and drop. The Java JDK releases include support for both these communications media.
    • Internationalization: – The JFC classes support different character sets such as Chinese, and Korean. This allows developers that can interact with users worldwide in their own languages.

What is Swing?

  • The Swing is an enhanced component set that provides replacement components for those in the original AWT and a number of more advanced components.
  • These components enable you to create user interfaces with the type of functionality that has become expected in modern applications.
  • Such components include trees, tables, advanced text editors, and tear off toolbars.
  • Swing also has special features. For example, using Swing, you can write a program that adopts either the look-and-feel of the host platform or that uses a common look-and-feel written especially for the Java programming language (Metal).
  • In fact, you can create your own look-and-feel from scratch, or modify an existing one and plug it in to your program, either hard coded or by the user or system administrator selecting a look-and-feel at runtime.

Note: – The term look-and-feel occurs frequently in this. Look refers to appearance of components, while feel refers to the way they react to user actions, such as mouse clicks. Writing a look-and-feel refers to writing the necessary classes to define new appearance and input behavior.

Pluggable Look-and-Feel:-

  • Pluggable look-and-feel enables developers to build applications that execute on any platform as if they were developed for that specific platform.
  • A program executed in the Microsoft Windows environment appears as if it was developed for this environment; and the same program executed on the UNIX platform appears as if it was developed for the UNIX environment.
  • Developers can create their own custom Swing components, with any kind of look-and-feel that they choose to design.
  • This increases the consistency of applications and applets deployed across platforms.
  • An entire applications GUI switch from one look-and-feel to a different one at runtime.
  • Pluggable look-and-feel provided by the Swing components is facilitated by their underlying architecture.
  • The next section describes the Swing architecture and explains how it facilitates the pluggable look-and-feel.

Swing Architecture:-

  • Swing components are designed based on the Model-View-Controller (MVC) architecture. The Swing architecture is not strictly based on the MVC architecture but has its roots in the MVC.

Model-View-Controller Architecture:-

  • As per the MVC architecture, component can be modeled as three separate parts.
  1. Model: – The Model stores the data used to define the components.
  2. View: – The View represents the visual display of the component. This is governed by the data in the model.
  3. Controller: – The controller deals with the behavior of the components when a user interacts with it. This behavior of the any updates to the model or view.

Java GUI's Using the Swing APIJava GUI's Using the Swing API

  • Theoretically, these three types of architecture (Model, View, and Controller) should be represented by different class type.
  • But, practically, this turns out to be very difficult because of the dependencies between the view and the controller.
  • The role of the controller is heavily dependent on the implementation of the view. This issue is addressed by the separable model architecture.

Separable Model Architecture:-

  • The Swing components follow separable model architecture. In this architecture the view and the controller are merged as a single composite object, because of their tight dependency on each other.
  • The model object is treated as a separate object just like in MVC architecture.

The given below shows the separable model architecture:

 The UI Object in figure is referred to as UI delegate. With this architecture it is possible to delegate a few responsibilities of the component to an independent UI Object.

  • This explains how the pluggable look-and-feel is facilitated by the Swing components.
  • The components make the visual appearance of the components the responsibility of the independent UI Object.
  • So the UI Object of the installed look-and-feel is independent from the components look-and-feel.

Sourabh Bhunje

Sourabh Bhunje, B.E. IT from Pune University. Currently Working at Techliebe. Professional Skills: Programming - Software & Mobile, Web & Graphic Design, Localization, Content Writing, Sub-Titling etc.

Leave a Reply