14.2 Graphical Objects


14.2 Graphical Objects

When running GUI applications, a typical user looks at some graphical objects on the screen. Some of these objects display data of the program. Other graphical objects allow the user to enter data to the program. The user can also point and click with other graphical objects, and in this way, can interact with the program in execution. The most relevant objects that form part of a graphical user interface are:

  • Containers

  • Components

  • Events

  • Listeners

14.2.1 Components and Containers

Simple GUIs have only containers and components. Graphical interfaces that only include these objects present very limited user interaction. With events and listeners, in addition to components and containers, the full advantage of user interaction is made available.

A container is an object that can hold graphical components and smaller containers. A container object also allows its contained objects to be arranged in various ways. This arrangement of objects is facilitated by special objects called layout managers. Examples of container objects are frames and panels.

A component is a small graphical object that displays data, allows the user to enter data, or simply indicates some condition to the user. Component objects are usually arranged with other components in a container object. Examples of component objects are buttons, labels, and text fields.

Figure 14.1 shows the basic structure of a simple graphical user interface. The frame is divided into two panels, and each panel contains several graphical components.

click to expand
Figure 14.1: General structure of a GUI.

14.2.2 Importing the AWT and Swing Libraries

A package is a group of related classes. A library package is a predefined group of classes that are available on the current environment.

Note

Several precompiled Java classes are provided in various packages with the Java compiler. Other library packages are provided by third parties.

The import statement is required by any class definition that needs access to one or more classes in a library package. Most programs that include GUI, need to access the two Java class packages, AWT and Swing. In the programs, an import statement must be included at the top of a class definition.

The following two lines of code are the ones normally required by programs that access the graphical libraries AWT and Swing. The import statements shown give access to all the classes in the two packages.

       import all java.awt       import all javax.swing 




Object-Oriented Programming(c) From Problem Solving to Java
Object-Oriented Programming (From Problem Solving to JAVA) (Charles River Media Programming)
ISBN: 1584502878
EAN: 2147483647
Year: 2005
Pages: 184

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net