Graphical User Interface Components with AWT and Swing

Introduction

Java provides a huge library for graphical programming. Earlier object oriented languages used to have a very poor user interface.
In Java, AWT (Abstract Window Toolkit) is used for GUI programming.

Abstract Window Toolkit (AWT)

AWT is a platform dependent API to develop GUI or window-based application. It comes in Java 1.0 for graphical programming.
AWT provides the better look for user environment. It is a heavyweight component.
There are various classes in java.awt package.
For example: Applet, Button, Canvas, Menu, Label, List, Frame, Panel, Window etc.

Swing

Swing is also used for Java graphics. Java Swing is one of the parts of Java Foundation Classes (JFC). JFC provides the rich graphics programming for the Graphical User Interface.

Features of Swing

  • It is Lightweight component.
  • The look of the swing programming is pluggable.
  • Debugging support.
  • The main feature of the Swing is Model View Controller (MVC).
There are multiple controls provided by Swing.

  • Images Buttons
  • Sliders
  • Toolbars
  • Color choosers
  • Progress bars
  • Trees

AWT vs. Swing

AWTSwing
The components of AWT start without letter J. For example: Applet, Button, Canvas, Menu, Label etc.The components of the Swing begin with letter J. For Example: JButton, JApplet, JCheckBox etc.
AWT components are the Heavyweight components.Swing components are the Lightweight components.
AWT components are platform dependent.Swing components are less dependent on platform and use less of the native GUI resource.
AWT components are not very good in look and feel.Swing components are better in look and feel.
It doesn’t have innovative tools.Swing has innovative tools such as Border in any type (setBorder()), Graphical debugging, pluggable look etc.
AWT doesn’t follow MVC architecture.Swing follows the MVC architecture.