AWT and SWING in Java

AWT and SWING in Java

AWT

It stands for Abstract Window Toolkit. It depends on the platform. In other words, it is a platform-dependent API using which one can create window-based applications. AWT was developed by Sun Microsystem in 1995.

Components

The components of AWT are the following:

Button (java.awt.button)

This component is responsible for creating a button by calling a constructor method. The most fundamental button constructor accepts a string as input and provides a text title to the button object.

Checkboxes(java.awt.Checkbox):

A checkbox contains two states: On and Off. Whenever a checkbox event occurs, the state of the button is returned as the object argument.

Labels(java.awt.label):

This component is quite useful for including a text description on the applet.

Textfields(java.awt.TextField):

It provides areas where text can be inserted by the user. This component is specifically used to receive and display text messages.

SWING

Swing is a kind of GUI (graphical user interface) using which we can create a variety of applications in Java. The components of Swing don’t rely on any platform. In other words, they are platform-independent. Using Swing we can create buttons and scroll bars. It provides the support of robust packages using which we can create desktop applications in Java.

Components

The components of Swing are the following:

ImageIcon:

This component is specifically used to make an icon-sized image with reference to an image that resides at the source URL.

JLabel:

This component is used to display read-only text or images in the user interface. No event is generated by this component.

JComboBox:

This component is used to display a dropdown of a number of options.

JFileChooser:

This component provides a utility to select files. Using this component, we can select a from the local system.

Difference between AWT and Swing

AWT

Swing

This is an API using which we can create GUI applications in Java.

This is a part of the Java Foundation Class and can be used to create a variety of applications.

It is platform-dependent.

It is platform-dependent.

AWT takes more execution time as compared to Swing.

The swing takes less execution time as compared to AWT.

It doesn’t support the MVC pattern.

It supports the MVC pattern.

It provides less functionality as compared to Swing.

It provides more functionality as compared to AWT.

The components of AWT are less powerful as compared to Swing.

The components of Swing are more powerful as compared to AWT.

Conclusion

In this article, we highlighted the differences between AWT and Swing. I hope this article has helped you to strengthen your knowledge in the field of Java.