Java Graphical User Interfaces

Swing

A Swing graphical user interface (GUI) is a tree.

The root of the tree is a top-level container (instances of JFrame, JApplet, or JDialog).

All other nodes are instances of JComponent subclasses.

JComponents can be containers (JPanel, JFileChooser, JMenuBar, JMenu, JInternalFrame, etc.) or controls (JButton, JMenuItem, JTextField, JLabel, JTable, etc.)

Containers are parent nodes in the GUI tree. Controls are leaf nodes.

Model-View-Controller Architecture

Many desktop applications instantiate the Model-View-Controller architecture:

In this design the Model encapsulates the application data and logic, the View is the GUI, and the Controller executes commands coming from the view by querying and updating the model.

In Swing, controllers implement the ActionListener interface and are therefore called listeners. Views extends the JPanel class and are sometimes called control panels:

Event Delegation

A controller registers with every control in the view that it is interested in. It's possible that one controller could register with every control or that every control has its own controller. When a control is tweaked by a user, every registered controller is notified. This is called event delegation.

Example

All of these concepts are explained in detail by the following example:

Temperature Converter