Unit2 AWTpptx 2024 09 05 08 04 44
Unit2 AWTpptx 2024 09 05 08 04 44
AWT
Computer
Engineering
Diploma
Toolkit)
Window Toolkit)
09CE1504
AWT & Swing
Abstract Window Toolkit is known as AWT.
Lightweight
Swing -
Demo
Content Pane
JComponent
JFrame
JComboBox, JLabel
JList, JTextComponent
Swing - JMenuBar
GUI Properties
Componen Methods
JButton
t API
Events
(1) Create it
Instantiate object: b = new JButton(“press me”);
JFrame
JPanel
Anatomy JFrame
of an JButton
containers
Applicatio JPanel
n GUI
JLabel
JButton JLabel
(1) Create: Listener
Frame
Panel
JLabel JButton
Components
Build from Listeners
bottom up JPanel
(2) Add: (bottom up)
listeners into components
components into panel
panel into frame
JFrame
JFrame f = new JFrame(“title”);
JPanel p = new JPanel( );
JButton b = new JButton(“Submit”);
Submit
f.setSize(400,400);
f.setVisible(true);
}
}
The process of determining the size and position of
components.
1) BorderLayout
2) BoxLayout
Layout 3) FlowLayout
Managem 4) GridLayout
ent (Cont)
Has five areas available to hold components
north, south, east, west and center
Layout
All extra space is placed in the center area
Manageme Only the center area is affected when the container is resized.
nt (1)
Default layout manager of content panes.
Border
Layout
Places components in a single row (left to right) or
column (top to bottom).
Respects component’s maximum size and alignment
Layout hints.
Manageme
nt (2) Box
Layout
Places components from left to right, starting new
rows if necessary.
Default LayoutManager of JPanel.
Layout
Manageme
nt (3) Flow
Layout
Places components in a requested number of rows
and columns.
Components are placed left-to-right and top-to-
bottom.
Layout
Forces all components to be the same size
Manageme as wide as the widest component's preferred width
nt (4) Grid as high as the highest component’s preferred height
Layout
Thank you….