3. Welcome!
Are you excited for a fun
learning session?
Unit Outcomes
Develop Graphical User (GUI) programs using AWT
Components for given component
Create frame window with specified AWT
components
Develop programs using menu and Dialog Boxes for the given
Arrange the GUI components using specified AWT
components
4. What is AWT ?
Abstract Window Toolkit (AWT) is one of java's largest packages
AWT containes many classess and methods
We can create user interface with AWT.
AWT classes are present in java.awt package
AWT is use to create and manage windows
6. Component object remembers
foreground,background, text font
Component
Class
Top of AWT heirarchy All UI elements are
subclass of this class
Has 100 public methods
Manages events such as
mouse and keyboard i/p
7. Container
Class
This class is sublcass of
Component class
Has methods Component
objects to be nested
within it.
This class is responsible for
laying out components
Other conatiner objects
can be stored inside of a
container
It uses various layout managers
8. Panel Class
This class is sublcass of
Container class
No new methods, simply
implements Container
Applet output is drawn on
surface of Panel object
Panel is superclass for
Applet
Other components can be added to a
Panel object by its add( ) method
Panel window doesn't contain title bar,
menu bar, or border
9. Window Class
This class creates a top
level window
A top level window is not
contained in any other
object
It directly sits on desktop
Generally we don't create
Window object directly
Instead we use sublcass of Window called Frame
10. Canvas Class
Canvas is a not a part of
heirarchy
Canvas is a blank window on
which you can draw
It is other type of window
11. Creating Frame windows
Setting window's dimensions
Frame( )
Frame( String title)
Frame class constructors
void setSize(int newWidth, int newHeight)
void setSize(Dimension newSize)
Dimension getSize( )
12. Creating Frame windows
Setting a window's title
void setVisible(boolean visibleFlag)
Hiding and showing a window
void setTitle(String newTitle)
setVisible(false)
windowClosing( )
Closing a Frame window
15. AWT controls and layout managers
Controls are components that allows to interact with the
application
Layout managers automatically positions components
within a container
Menu bar creates a drop down menus of options from
which we can select options
16. AWT controls List
AWT supports following types of controls
Labels
Push buttons
Check boxes
Choice list
Lists
Scroll bars
Text Editing
18. Labels
A label is an object of class/type Label
It contains a string displayed on screen
It is passive control and doesn't support any interaction
Constructors of Label class
Label( ) throws HeadlessException
Label(String str) throws HeadlessException
Label(String str, int how) throws HeadlessException
19. Functions & Example of Labels
void setText(String str)
String getText( )
void setAlignment(int how)
void setAlignment(int how)
int getAlignment( )
20. Buttons
A push button is an object of class/type Button
A push button contains a label
It can be pressed to generate event
Button( ) throws HeadlessException
Button(String str) throws HeadlessException
void setLabel(String str)
String getLabel( )
22. Checkbox
A checkbox is an object of class/type Checkbox
It has a small box which can be checked
Checkbox has label
It's state can be changed by clicking it
Check boxes can be used individually or part of a group
24. Functions & Example of Checkbox
boolean getState( )
void setState(boolean on)
String getLabel( )
void setLabel(String str)
25. CheckboxGroup
Creates mutually exclusive check boxes
Also called as radio button, only one can be selected
First we need to create group and then individual checkboxes
Check box groups are objects of class / type CheckboxGroup.
Checkbox getSelectedCheckbox( )
void setSelectedCheckbox(Checkbox which)
setSelectedCheckbox( ).
getSelectedCheckbox( ).
27. Choice Controls
popup list is created using Choice class
Each item the popup list is string and left justifiable
void add(String name)
String getSelectedItem( )
int getSelectedIndex( )
int getItemCount( )
void select(int index)
void select(int index)
String getItem(int index)
29. Lists
Scrolling selection list is created using List class
Multiple selection of options are available
Can show any number of choices in visible window
List( ) throws HeadlessException
List(int numRows) throws HeadlessException
List(int numRows, boolean multipleSelect) throws HeadlessException
30. Functions in Lists
void add(String name)
void add(String name, int index)
String getSelectedItem( )
int getSelectedIndex( )
String[ ] getSelectedItems( )
int[ ] getSelectedIndexes( )
int getItemCount( )
void select(int index)
void select(int index)
String getItem(int index)
32. Scroll Bars
Scroll bars are used to select continuous values between specified
minimum and maximum
The current value of the scroll bar relative to its minimum and
maximum values is indicated by the slider box (or thumb) for the
scroll bar.
Scroll bars are created using Scrollbar class
Scrollbar( ) throws HeadlessException
Scrollbar(int style) throws HeadlessException
Scrollbar(int style, int initialValue, int thumbSize, int min, int max)
throws HeadlessException
33. Functions of Scrollbar
void setValues(int initialValue, int thumbSize, int min, int max)
int getValue( )
void setValue(int newValue)
int getMinimum( ), int getMaximum( )
void setUnitIncrement(int newIncr)
void setBlockIncrement(int newIncr)
getAdjustmentType( )
35. TextField
Single line text entry is created using TextField class
Also called edit control
TextField class is a subclass of TextComponent class
TextField( ) throws HeadlessException
TextField(int numChars) throws HeadlessException
TextField(String str) throws HeadlessException
TextField(String str, int numChars) throws HeadlessException
36. Functions of TextField class
String getText( )
void setText(String str)
String getSelectedText( )
void select(int startIndex, int endIndex)
boolean isEditable( )
void setEditable(boolean canEdit)
void setEchoChar(char ch)
38. TextArea
Multiline editor is created using TextArea class
TextArea( ) throws HeadlessException
TextArea(int numLines, int numChars) throws HeadlessException
TextArea(String str) throws HeadlessException
TextArea(String str, int numLines, int numChars) throws HeadlessException
TextArea(String str, int numLines, int numChars, int sBars) throws
HeadlessException
39. Functions & Example of TextArea
void append(String str)
void insert(String str, int index)
void replaceRange(String str, int
startIndex, int endIndex)
TextArea class is subclass of
TextComponent class
40. Layout Managers
Layout manager decides where to place controls in window
Each container object has layout manager associated with it
Layout manager is instance/object of any class that implements
LayoutManager interface
void setLayout(LayoutManager layoutObj)
void setLayout(LayoutManager layoutObj)
If setLayout() function is not used then default
layout manager is used
42. Question Spot !!
Identify AWT controls and Layout managers for
User Interface of Student Registration System of
Government Polytechnic Gadchiroli
43. Components are placed left to right
and top to bottom like text editor
FlowLayout( )
FlowLayout
It is default layout manager
FlowLayout(int how)
FlowLayout(int how, int horz, int vert)
45. BorderLayout
Border layout devides
window into 5 components
These are north, south , east, west
and center
BorderLayout( )
void add(Component compObj, Object region)
BorderLayout(int horz,
int vert)
47. Insets
Insets is used to provide small amount of space betweeen the container
that holds your components and the window that contains it.
getInsets( ) method of container class is used for this.
Insets(int top, int left, int bottom, int right)
Insets getInsets( )
48. GridLayout
GridLayout uses two
dimensional grid
Number of rows and columns are
defined
GridLayout( )
GridLayout(int numRows, int numColumns, int horz, int vert)
GridLayout(int numRows,
int numColumns)
50. CardLayout stores various
other layouts Each layout is like card in a deck
CardLayout( )
The cards held in object off
class/type Panel
CardLayout(int horz, int vert)
CardLayout
The cards that form the deck
are also typically objects of
class/type Panel
53. We can specify relative
position of components
within cell inside grid
Each component has different size
void setConstraints(Component
comp, GridBagConstraints cons)
Location,size, constraints of
components is contained in object of
GridBagConstraints class
Each row in grid have different
no. of columns
GridBagLayoutGridBagLayout( )
55. Generally top level window
has menubar associated
with it
Menu bar displayes list of top level
menu choices
Menu is subclass of MenuItemEach Menu object contains list of
MenuItem objects
Menu bar containes one or
more Menu objects
Three classes use:
MenuBar, Menu,
MenuItem
Menu Bars,Menus &
Menu Items
56. Checkable menu items can
also be created using
CheckboxMenuItem class
Menu( ) throws HeadlessException
MenuItem(String itemName)
throws HeadlessException
Menu(String optionName, boolean
removable) throws HeadlessException
Menu(String optionName)
throws HeadlessException
MenuItem( ) throws
HeadlessException Menu Bars,Menus &
Menu Items
60. Dialog boxes are used to get user input
Modeless dialog box: can access
other parts windows
Model dialog box: cannot access
other part of windows
They are child windows of top
level windows
Dialog Boxes
Dialog boxes don't
have menu bars
They function as
frame windows
Dialog(Frame
parentWindow, boolean
mode)
Dialog(Frame
parentWindow, String
title, boolean mode)
62. Object of FileDialog class is used to
created file dialog box
String getFile( )
It is generally provided by
operating system
FileDialog
FileDialog(Frame parent)
String getDirectory( )
FileDialog(Frame parent,
String boxName, int how)FileDialog(Frame parent,
String boxName)
67. Summary of Class
Unit Recap 1
Types of
Winodws
Unit Recap 2
Creating
windowed
programs
Unit Recap 3
AWT Controls.
2
1
3
4
Unit Recap 4
Layout
Managers