Skill-Building Exercises


Summary

A component is any GUI object that has a visible representation on the screen. A container is a component that can “contain” other components. A top-level container is a container that exists on the computer screen and can’t be contained by another container. Java GUI applications must start with a top-level container otherwise known as a window. There are three types of windows: Window, Frame and Dialog. Their Swing counterparts are JWindow, JFrame and JDialog. All Swing top-level containers have a content pane to which all GUI components must be added. JFrame is comprised of a title bar, border, optional menubar and a content pane. Most Swing applications will begin with JFrame since it isn’t dependent on the existence of a previously created window.

Layout managers position components in containers and automatically reposition them as conditions change. All containers can be assigned a layout manager through the method setLayout(LayoutManager). There are two layout manager interfaces defined by the AWT: LayoutManager which positions components based on the order in which they are added to the container, and LayoutManager2 which positions them according to constraints objects. Flow-Layout and GridLayout are examples of the former type. FlowLayout arranges components in a container similarly to the way a text processor arranges text in a page. GridLayout divides the container into a grid of uniformly sized cells and places components one per cell. BorderLayout and GridBagLayout are constraints-based layout managers. BorderLayout takes up to five components. It allows the component placed in the center to fill all available space as the container resizes while the other components are given only as much space as is necessary. GridBagLayout accepts a GridBagConstraints object on a per-component basis, encapsulating many options for how each component should be placed in its container. There are many other layout managers and it is even possible to write your own by implementing the LayoutManager or LayoutManager2 interface.

Components provide the visual representation of an application’s data, and they provide the user with the means to graphically communicate complex instructions to an application. All Swing components except for the top-level Swing containers extend from javax.swing.JComponent. Although all Swing components are technically containers, JPanel is the Swing container to which we should add components.




Java For Artists(c) The Art, Philosophy, and Science of Object-Oriented Programming
Java For Artists: The Art, Philosophy, And Science Of Object-Oriented Programming
ISBN: 1932504052
EAN: 2147483647
Year: 2007
Pages: 452

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