THE Java™ Programming Language, Fourth Edition

(Jeff_L) #1

  • java.util.zip Classes for reading and writing ZIP files.


Further packages exist outside the java package of the platform, in what are known as the standard
extensions, for example:


javax.accessibility A framework for developing GUIs that are more accessible to people
with disabilities.



  • javax.naming Classes and subpackages for working with directory and naming services.

  • javax.sound Has subpackages for creating and manipulating sounds.

  • javax.swing The Swing package of GUI components.


And there are packages that provide interaction between the platform and other environments:


org.omg.CORBA Classes for the Common Object Request Broker Architecture (CORBA), object
request brokers (ORB's).



  • org.omg.CosNaming The Common Object Service's naming classes.


Other versions of the platform, such as the Java™ 2 Platform Enterprise Edition, contain even more packages.


This book cannot be large enough to contain full coverage of every one of these packagessome of them
require complete books of their own. This chapter discusses some of the java subpackages not otherwise
covered in this book, giving an overview of the purpose and contents, as well as some of the other packages
we have listed. All these packages are covered in detail in your local documentation and the java packages
are covered in the volumes of The Java™ Class Libraries, Second Edition. Most of the java packages,
including the AWT and applet packages and some extensions such as Swing, are taught in the different
versions of The Java™ Tutorial. These books and all others cited in this chapter are part of this official series
of documentation from the sourcethe people who invented the Java programming language, its virtual
machine, and many of its packages.


25.1. java.awt The Abstract Window Toolkit


The Abstract Window Toolkit allows you to write graphical user interfaces (GUIs) that will run on every
system in a reasonable way. The AWT displays GUI components (such as buttons, labels, and text fields) using
(by default) the local platform's look and feel, showing Macintosh buttons on a Mac, Motif buttons on X
platforms, Windows buttons on Windows systems, and so on.


For this to work, you may need to change how you think about laying out your GUI. You may be accustomed
to interactive tools that let you place the various GUI components on the screen exactly where you want them
to be. Such absolute placement will not work for a portable interface because, for example, the size of a button
is different on different systems. When your interface is used on a system other than the one on which you
designed it, some buttons will overlap and others will have ugly gaps between them.


Although you can use absolute placement in AWT, it is not recommended. When you place a component into
an AWT display frame, the frame's layout manager decides where to put it. Almost all the layout managers
provided with the AWT use relative placement: Components are placed and sized relative to other components.
All the provided layout managers implement either the interface LayoutManager or its extended interface
LayoutManager2. Layout managers range from the simple (FlowLayout adds components to a line until
they don't fit and then starts a new line) to the sophisticated (GridBagLayout has a great deal of
flexibility). You can also write your own layout manager.


Instead of thinking about where a check box should go on the screen, you should think about how it should be
placed relative to other components. Then choose a layout manager for the frame in which the check box will

Free download pdf