The GUI toolbox Swing

Examples

Note : the two examples SwingApplication and CoordinatesDemo come from the tutorial about the SDK5.0. These examples are no longer included in the current tutorial, which is mainly based on the use of the IDE NetBeans.

Hello World

The two following examples give the same result, but using two different implementations for handling the "action" event on the button :
  1. In this version , the main class implements ActionListener and then, is used as instance of ActionListener to listen the button.
  2. In this version, the instance of ActionListener is written using an anonymous inner class.

SwingApplication

This example of a simple application comes from the Java tutorial.

Layout Demos

These examples come from the Java tutorial. The most useful layout managers are (in my opinion) :

Coordinates Demo

This example, which explains how to draw in a component, comes from the Java tutorial.

Line

This example, shows how to draw an line segment starting where you have pressed the mouse button and ending where you have released it.
A similar example, using Graphics2D instead Graphics.

Browser

This example shows how to implement a simple web browser. More specifically, it contains a generic history.