Java Reference
In-Depth Information
Introduction
1
1.1
General
Modern operating systems such as Microsoft's Windows, Apple's MacOS, and the
different Unix-based versions such as Linux or Solaris use a graphical interface
to communicate with the user. The communication consists of information dis-
played by programs and actions and commands issued by the user. This topic is an
introduction to graphic programming in Java. It is assumed that the reader knows
the basic concepts of Java such as object-orientation, inheritance, interfaces, ex-
ceptions and use of packages.
There are two libraries for graphics components in Java: the Abstract Win-
dowing Toolkit (AWT) and Swing . The first is the older one. It contains all the
components needed to design graphical user interfaces. However, using AWT is
not easy and the library is not free of bugs. The components of the Swing library
are easier to work with and are much better implemented. Some Swing compo-
nents need classes from the AWT library. To make these classes available we have
to import them by
import java.awt.*;
import javax.swing.*;
Sometimes it is advisable not to include the whole library by using * (because it
is so large) but only the classes needed.
Here we introduce the fundamental graphical components of the Swing library.
The aim is to enable the reader to design an interactive graphical interface. This
includes displaying graphics and text, making buttons react and the use of the
mouse. We present only the most important graphical components and control
concepts in this topic. There are many more components that are not consid-
ered. Only the essential features of the components are described. Information on
additional components features can be found in the Java documentation.
Important facts and sources of frequent errors are marked by a '!' in the margin.
!
The example programs are designed independent of a development environ-
ment. They can be compiled and run from the command line. All programs are
contained in the main package its for 'Introduction to Swing'. This package con-
tains further (sub-)packages, each of which contains the programs for a specific
Search WWH ::




Custom Search