Gui Programming in Java523
Gui Programming in Java523
GUI Programming
in Java
Presented by Thanh Pham
thanh.phamhong@niithoasen.com
06/2007
B070038 – NIIT Quang Trung
Contents
1 Basic Concepts
3 Layout Manager
4 Event Handling
5 Other References
Basic Concepts
Basic
Basic Concepts
Concepts
Similarities:
Tools provided by Java for developing
interactive GUI applications
Provides GUI components that can be used in
creating Java applications and applets
Abstract Window Toolkit (AWT) vs. Swing
MessageBox
InputBox
Create Frame (AWT)
Create Frame (Swing)
CenterFrame
Exercises
AWT
AWT and
and Swing
Swing Control
Control Components
Components
TextField
TextArea
Button
List
CheckBox
Choice
Labels
Demo
FrameWithControl
Swing Control Components
JFrameWithControl
Exercises
Layout Managers
Layout
Layout Managers
Managers
BorderLayout Manager
BorderLayout is the default layout of the Frame class.
The BorderLayout layout manager divides the container into
north, south, east, west, and centre regions.
You can place five components or controls in each part.
Java provides the BorderLayout class to apply the border layout
to the components.
The setLayout() method is used for applying border layout to a
container.
You specify the directions for the BorderLayout using the
BorderLayout.NORTH, BorderLayout.SOUTH,
BorderLayout.EAST, BorderLayout.WEST, and
BorderLayout.CENTER constants.
You can use the following constructors to create an instance of
the BorderLayout class:
BorderLayout()
BorderLayout(int h, int v)
Layout Managers
GridLayout Manager
The grid layout is the layout that divides the container
into rows and columns.
The intersection of a row and a column of the grid
layout is called cell.
The GridLayout class of Java enables you to create a
grid layout.
All the components in a grid are of the same size.
You can use the following constructors to create an
instance of the GridLayout class:
• GridLayout()
• GridLayout(int r, int c)
• GridLayout(int r, int c, int h, int v)
Demo
FlowLayout
BorderLayout
GridLayout
To be continued
To be continued….
References