The GUI Libraries


The second group of packages from the J2SE libraries we will discuss are the GUI libraries. Java provides a rich set of libraries for creating GUIs that can provide an alternative for command line input or reading input from a file. The ability to create GUIs is yet another nice feature of the Java language in that an application and its front-end GUI can be written in the same programming language. This avoids any integration issues that can arise if you are mixing and matching languages. An introduction to Java GUI development is provided in Chapter 26, but a snapshot of some of the important GUI packages is given here.

java.awt

The java.awt package contains the older (Java 1.1) GUI component and support classes. Java GUI application development as of Java 1.2 has largely moved to the more powerful and versatile Swing classes; however, some Swing components , particularly the high-level windows , inherit from Abstract Window Toolkit (AWT) superclasses. This package also contains the Dimension and Rectangle classes that are used to size GUI components. The java.awt package also contains the Color and Font classes.

java.awt.event

The java.awt.event package defines event classes and listeners. When a user interacts with a GUI component, the system creates event objects that contain information about the interaction. If an appropriate event listener is registered with the GUI component, the event object will be sent to the listener which will then process and respond to the event. Originally developed for AWT GUI components, the event capability defined in the java.awt.event package is also utilized by many of the Swing GUI components. For example, both Button and JButton components can generate instances of the ActionEvent class that is contained in the java.awt.event package.

javax.swing

The javax.swing package contains the Swing GUI component and support classes. Swing components are much more powerful and versatile than their AWT counterparts. For one thing, the Swing GUI containers have different panes or layers on which you can place your components. The javax.swing package contains interesting new container classes including JSplitPane and JTabbedPane .

The javax.swing package has a greatly expanded set of GUI components from which to choose. In the java.awt package there is only one class that represents a button and many of the style features, such as the component border, are hard-coded into the class. The javax.swing package defines many kinds of buttons including the JButton , JToggleButton , and JRadioButton classes. You have a lot more freedom to define the look and feel of Swing components. You can select or customize the border around the component, for example.

javax.swing.border

With Swing, you can be creative when it comes to assigning borders to your GUI components. The javax.swing.border class provides classes to generate raised, line, matte, etched, empty, titled, or compound borders.

javax.swing.event

Swing GUI components are more diverse, versatile, and powerful than their AWT counterparts. It is only natural that they would need additional event classes to support their enhanced functionality. Among other things, the javax.swing.event package defines events and event listeners for JTable and JTree components, internal frames , pop-up menus , documents, and cell editors. There are additional event classes and interfaces for menu and list components.

javax.swing.table

One of the powerful Swing components is the JTable class, defined in the javax.swing package, which allows you to represent data in a table-like format. The javax.swing.table package provides support classes and interfaces for JTable objects. Included are classes and interfaces to define the table and table column models, the table cell renderer, and the table cell editor.

javax.swing.text

The javax.swing.text package provides classes and interfaces for working with editable and noneditable text components. Included is the Document interface that defines the document model for Swing text components. The classes defined in this package include the editor kit, view, highlighter, and document filter classes.

javax.swing.tree

Another powerful Swing component is the JTree class that allows you to represent data in a tree-like structure. The javax.swing.tree package contains interfaces and classes that define the nodes, model, selection model, cell editor, and cell renderer of a JTree .



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