The Java GUI Libraries


Before we demonstrate the process of creating a GUI, let's talk about the Java GUI libraries, what is in them, their history, and some of the design philosophy behind Java GUI development. The older Java GUI components , used during the Java 1.0 and 1.1 releases, can be found in the java.awt package. The java.awt GUI components are limited in functionality and flexibility. A lot of the style and features of the AWT components are hard-coded and can't be changed. For example, the size of a Button object and its border style is determined by the system and can't easily be altered . The AWT containers were similarly limited in what you could do with them. They consisted of only one layer and components are added directly to the container.

As Java became more sophisticated so did its GUI capability. The Swing packages were introduced with Java 1.2. These contain an entirely new class of GUI components. While the AWT components rely on a component peer, written in a non-Java language such as C, to display the component on the screen, Swing components are pure Java. One great advantage of the Swing components is that much of the control over what a component looks like or does has been turned over to the programmer. You can change a component's border, its size, even how it looks when it is rendered on the screen. You can create custom components by modifying the data model of an existing component.

Swing containers were redesigned as well. Instead of having only one layer on which to add components, Swing containers have multiple layers called panes with which to work. There are three types of panes ”content, layered, and glass. You no longer add components directly to the container, instead you place them on one of the panes associated with the container. Using the different layers of a Swing container you can make components appear to be stacked , or temporarily disable the GUI display.

The Swing GUI components have not totally forgotten their AWT roots. The Swing components borrowed what functionality they could from their AWT predecessors. The superclass of the Swing components, JComponent , is itself a subclass of the AWT component superclass, Component . The high-level Swing container classes JFrame , JWindow , and JDialog are direct subclasses of AWT Frame , Window , and Dialog , respectively.

One aspect about Java GUIs that is different from the GUI capability of other languages is that Java retains a fair amount of control over how the GUI will look and behave. For example, you do not position components at a fixed location on the screen. An entity called a layout manager determines the component positions according to its own internal rules. If you change the size of the GUI window, for instance, the layout manager will likely change the location of the components as well. Java also has internal rules about style. You can make suggestions as to things like component size or margins, but the system reserves the right to ignore you if what you want to do violates its internal guidelines.

For the GUI that we will develop in this chapter, we will use Swing GUI components, but we will need to use some event handling and support classes from the java.awt package. Keep in mind that this is a relatively simple GUI example. The Java GUI capability is quite extensive . We won't discuss things like data models and will only briefly touch on subjects such as event handling. That all being said, let's create a GUI.



Technical Java. Applications for Science and Engineering
Technical Java: Applications for Science and Engineering
ISBN: 0131018159
EAN: 2147483647
Year: 2003
Pages: 281
Authors: Grant Palmer

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