Java JFC Swing Introduction


Swing Introduction: JFC stands for Java Foundation Classes. It is a collection of five APIs : AWT, Accessibility, 2D API, Drag and Drop and Swing. Similar to JFC are NFC (Netscape Foundation classes) or IFC(Internet Foundation Classes, of course with different functionality).

AWT API is used to display GUI components which is the original toolkit supplied by Java. AWT provides the foundation upon which the rest of the JFC is built. AWT components lack many GUI features which other GUI technologies give. For example, we cannot place an image on the button or change the border of a button. All these are overcome in Swing. Swing adds many features to AWT components. To achieve this, designers added new classes and came out with a special packages javax.swing and javax.swing.event. It is preferred to know AWT before attempting Swing.

Accessibility API is used to map components according to screen setting in terms of pixels. It consists of classes that enable Swing components to interact with assistive(related) technologies for users.

2D API is used to display GUI components in two – dimensional and three – dimensional elevations. The border of a component can be drawn in different thicknesses styles.

Drag and Drop API is used in JavaBeans to drag components from ToolBox and placing them on to the BeanBox.

Swing API is a set of mostly lightweight components built on top of the AWT. Swing provides lightweight replacements for the AWT’s heavyweight components. Swing also supplies multiple components which AWT is lacking like JScrollPane, JPasswordField, JColorChooser etc. Swing offers a very attractive look and feel appearance for its components than AWT.

Swing Introduction: What is heavyweight component?

Whenever you create a AWT GUI component like a button, a call will to the underlying OS to get the design of the button. AWT does not maintain the structure and appearance of a button. It depends on the OS where the Java program is being executed. Java copies the look of the button and displays to the user. It is a very time consuming process. For this reason, AWT components are known as "heavyweight components".

Swing Introduction: Why Java AWT is designed to be heavyweight components?

It is all done by keeping in view of the user-friendliness (even by loosing performance). Think AWT got its own design of the button and you display it in a frame. Besides your Java frame, a Windows wizard exists with Windows style of button. Now user feels inconvenience by seeing two different styles of buttons. If Java frame gives the same type of button of Windows; you feel comfortable as you are using the same button with which you are quite a long time acquainted.

If you execute the same button program on three different OS, you get three different styles of buttons. It is for user’s convenience only. Some people (of always argument nature) argue, basing on this feature, Java is not platform independent language.

Note: At the outset, I find three reasons why Java execution is slower. 1) bytecode conversion to binary at the time of execution by JVM 2) String immutability 3) AWT components heavyweight nature.

Swing Introduction: Why AWT components have fewer features compared to other similar GUI environments?

As AWT components are heavyweight, designers took all the common features of GUI components that exist in all the OS. Suppose one OS supports an image on the button and if the other does not support. If I write a Java program with the image on the button, if the other OS does not support then what is the fate of the program when executed. Finally, the result is less features.

Swing Introduction: What is lightweight component?

Contrary to AWT components, the swing components maintain their own design, appearance, look and feel. They do not depend on the underlying OS. That is, a swing button program executed on any OS gets you the same design of button. For this reason, swing components are known as "lightweight components". As swing does not depend on the OS, it added a lot of features to its GUI components like adding images to components to look better and displaying a label in multiple rows with bullets (of HTML type) etc.

4 thoughts on “Java JFC Swing Introduction”

    1. JRE other name is Execution engine.
      JVM + Java API is known as JRE.
      JRE + Compiler is known as JDK.

      Compiler is responsible to generate platform independent bytecode from source code.
      JVM is responsible to convert bytecode to machine (platform) dependent binary code, execute and get output.

Leave a Comment

Your email address will not be published.