2. A graphical user interface (GUI) presents a pictorial
interface to a program, GUI's allow the user to work in a
more productive manner.
A GUI component is an object with which the user
interacts via the mouse or keyboard, below are some of
the Java GUI components
3.
4. Some of the basic GUI components are
JLabelAn area where uneditable text or icons can be displayed
JTextFieldAn area where the user inputs data from the keyboard,
this area can also display data
JButtonAn area that triggers an event when clicked
JCheckBoxA GUI component that is either selected or not
selected
JComboBoxA drop-down list of items from which the user can
make a selection by clicking an item in the list or typing into the box
JListAn area where a list of items is displayed from which the user
can make a selection by clicking once on any element in the list.
Double-clicking an element in the list generates an action event,
Multiple elements can be selected
JPanelA container in which components can be placed
5. Java Layout Managers
The GUI is made up of a number of components, the
Layout Managers affect the content pane.
Layout Managers are provided to arrange GUI
components on a container for presentation purposes.
This allows the programmer to concentrate on the basic
"look and feel" and lets the layout managers process
most of the layout details
6.
7. Several AWT and Swing classes provide layout managers
for general use:
1. BorderLayout
2. BoxLayout
3. CardLayout
4. FlowLayout
5. GridBagLayout
6. GridLayout
7. GroupLayout
8. SpringLayout
9. BorderLayout
The class BorderLayout arranges the components to fit
in the five regions: east, west, north, south and center.
Each region is can contain only one component and each
component in each region is identified by the
corresponding constant NORTH, SOUTH, EAST, WEST,
and CENTER.
Class declaration
Following is the declaration
for java.awt.BorderLayout class:
public class BorderLayout extends Object implements
LayoutManager2, Serializable
10. Here are the constructors defined by BorderLayout:
1. BorderLayout()
2. BorderLayout(int horz, int vert)
the first form creates a default border layout. The second
allows you to specify the horizontal and vertical space left
between components in horz and vert, respectively.
BorderLayout defines the following constants that specify
the regions.
BorderLayout.CENTER, BorderLayout.SOUTH,
BorderLayout.EAST, BorderLayout.WEST,
BorderLayout.NORTH
11.
12. CardLayout
The class CardLayout arranges each component in the
container as a card. Only one card is visible at a time, and
the container acts as a stack of cards.
Class declaration
Following is the declaration
for java.awt.CardLayout class:
public class CardLayout extends Object implements
LayoutManager2, Serializable
13. CardLayout provides these two constructors:
1. CardLayout()
2. CardLayout(int horz, int vert)
14.
15. FlowLayout
The class FlowLayout components in a left-to-right
flow.
This is the most basic layout manager, components are
placed from left to right as they were added, when the
edge is reached the components are put on the next line.
You can align the components left, right or center
(default).
Class declaration
Following is the declaration
for java.awt.FlowLayout class:
public class FlowLayout extends Object implements
LayoutManager, Serializable
16. Here are the constructors for FlowLayout:
1. FlowLayout()
2. FlowLayout(int how)
3. FlowLayout(int how, int horz, int vert)
The first form creates the default layout, which centers
components and leaves five pixels of space between each
component. The second form lets you specify how each
line is aligned. Valid values of how are as follows:
FlowLayout.LEFT
FlowLayout.CENTER
FlowLayout.RIGHT
17.
18. GridLayout
Introduction
The class GridLayout arranges components in a
rectangular grid.
Class declaration
Following is the declaration
for java.awt.GridLayout class:
public class GridLayout extends Object implements
LayoutManager, Serializable
19. GridLayout are shown here:
1. GridLayout()
2. GridLayout(int numRows, int numColumns)
3. GridLayout(int numRows, int numColumns, int horz, int
vert)
20. GridBagLayout
The class GridBagLayout arranges components in a
horizontal and vertical manner.
Class declaration
Following is the declaration
for java.awt.GridBagLayout class:
public class GridBagLayout extends Object implements
LayoutManager2, Serializable
21.
22. GroupLayout
GroupLayout is a layout manager that was developed for use
by GUI builder tools, but it can also be used
manually. GroupLayout works with the horizontal and vertical
layouts separately. The layout is defined for each dimension
independently. Consequently, however, each component
needs to be defined twice in the layout. The Find window
shown above is an example of a GroupLayout. .
Class declaration
Following is the declaration
for javax.swing.GroupLayout class:
public class GroupLayout extends Object implements
LayoutManager2
23.
24. SpringLayout
SpringLayout is a flexible layout manager designed for use by
GUI builders. It lets you specify precise relationships between
the edges of components under its control. For example, you
might define that the left edge of one component is a certain
distance (which can be dynamically calculated) from the right
edge of a second component.SpringLayout lays out the
children of its associated container according to a set of
constraints, as shall be seen in
Class declaration
Following is the declaration
for javax.swing.SpringLayout class:
public class SpringLayout extends Object implements
LayoutManager2