Java Swings and GUI
  • Java Swings and GUI

About the Product

Java Swings and GUI

Summary:

The note provides an overview of Java Swing and GUI (Graphical User Interface) development in Java. Swing is a lightweight GUI toolkit that offers a wide range of widgets for creating window-based applications. It is built on top of the AWT API and is entirely written in Java.

Java Swing provides platform-independent and lightweight components compared to AWT, which is platform-dependent and heavyweight. Swing supports a pluggable look and feel, offers a greater variety of components, and follows the MVC (Model-View-Controller) architecture.

The Java Foundation Classes (JFC) simplify the development of desktop applications by providing a set of GUI components. The hierarchy of Java Swing classes is explained, and commonly used methods of the Component class are highlighted.

The note includes examples of creating a simple Swing application using both association and inheritance approaches. It demonstrates how to create a JFrame (window) and add a JButton (button) to it.

Additionally, the note introduces the JComponent class, which serves as the base class for most Swing components, and provides information about its fields.

Excerpt:

Java Swings and GUI

Java Swing is a part of Java Foundation Classes (JFC) that is used to create window-based applications. It is built on the AWT (Abstract Windowing Toolkit) API and entirely written in Java.

Unlike AWT, Java Swing provides platform-independent and lightweight components.

The javax.swing package provides classes for java swing API such as JButton, JTextField, JTextArea, JRadioButton, JCheckbox, JMenu, JColorChooser etc.

Difference between AWT and Swing

There are many differences between java awt and swing that are given below.

No. Java AWT Java Swing
1) AWT         components are platform-dependent. Java swing components are platform-independent.
2) AWT components are heavyweight. Swing components are lightweight.
3) AWT doesn’t support a pluggable look and feel. Swing supports a pluggable look and feel.
4) AWT     provides fewer components than Swing. Swing provides more powerful components such as tables, lists, scroll panes, colour chooser, tabbed panes etc.
5) AWT doesn’t follow MVC(Model View Controller), where the model represents data, the view represents presentation, and the controller acts as an interface between the model and view. Swing follows MVC.