Swing: user interface programming

Swing is the part of java which is dedicated to the comunication with the user through windows.

The following window, for example, is the form we always complete with our user and password to login into an application, using the Swing library.

Inside this window we can identify three types of components:

  1. Labels: User and Password are labels.
  2. Text boxes: the two white boxes on the right of the labels are text boxes.
  3. Buttons: login and register are buttons.

There are also some predefined windows which are known as dialog boxes "Dialog":

This is a dialog box which displays a message; in this case "login failed". The following window is a dialog box to input data; the user in this case.

Let´s see how to develop this type of interfaces:

  1. How to use dialog boxes: showMessageDialog and showInputDialog
  2. User interface input data validation.
  3. Our first window; login example.
  4. We make the buttons work using Listeners.
  5. Anonymous inner class.