SlideShare a Scribd company logo
1 of 63
AWT :Abstract Window ToolKit
 AWT is collection of classes and methods that allows
to create & manage window.
 AWT provide support for Applet.
 AWT contains support for windows_ based Graphical Interface.
 To use the AWT classes & method we have to import
awt package as
import java.awt.*;
1RAJESHREE KHANDE
AWT:classes
 Different window classes are defined by AWT which add
functionality with each level.
Component
Container
Window Panel
Frame Applet
2RAJESHREE KHANDE
3RAJESHREE KHANDE
AWT:classes
 Component :
 It’ an abstract class.
 All GUI component that interact with user are
subclasses of component class.
 Defines various methods for managing event such
as keyboard & mouse input.
 Also defines attribute to store current foreground
& background colors and fonts
4RAJESHREE KHANDE
AWT:classes
 Container:
 Inherits various methods & attribute of component
class
 Having additional methods of nesting other
component object.
 A container position various GUI component
within it with the help of different Layout manager
5RAJESHREE KHANDE
AWT:classes
 Panel :
 It is a window which does not contain title bar,
menu bar, border.
 It is super class of Applet class.
 Any screen output written on applet is drawn on
the surface of panel object.
 AppletViewer provide titlebar & border to an
applet.
 We add GUI component such as buttons ,list box
to a panel.
6RAJESHREE KHANDE
AWT:classes
 Window :
 Window class is used to create top level window.
 Window object are not created directly.
 Subclass of window is used to place on desktop.
7RAJESHREE KHANDE
AWT:classes
 Frame:
 It is subclass of window.
 It has title bar , menu bar & border etc
 To create a normal window in Java application Frame class
is used.
 In Applet we does not use Frame class, since AppletViewer
provide titlebar, menubar & boarder to an applet.
8RAJESHREE KHANDE
AWT:classes
 Canvas:
 It is not subclass of window or panel.
 It is another type of window.
 This widow is blank window upon which we can
draw.
9RAJESHREE KHANDE
Layout Managers
 It is an object which determine the way that
component are arranged in frame window.
 It arranges a control within a window using some
type of an algorithm.
 Each window has a layout manager associated with
it.
10RAJESHREE KHANDE
Layout Managers
 LayoutManager is set by the setLayout() method
to a window.
syntax
void setLayout(LayoutManager layobj)
 If it is not set then default layout manager is used
 If layobj parameter set to null then control are
positioned manually using the setBound() method
11RAJESHREE KHANDE
LayoutManager Classes
1.FlowLayout
 Default frame layout.
 Places Components in successive rows in window fitting as
many as in each row as possible.
 When the row is full it start fitting the components on the
next row.
 This is similar to how word flow in text editor
 A small space is left in each component.
12RAJESHREE KHANDE
LayoutManager Classes :FlowLayout
 Following are constructor for FlowLayout.
1. FlowLayout()
Centers all component and leves 5 pixel space between each component
2. FlowLayout(int align)
Flowlayout.LEFT
Flowlayout.CENTER
Flowlayout.RIGHT
Flowlayout.LEADING
Flowlayout.TRAILING
3. FlowLayout(int align, int hspace, int vspace)
 Example
13RAJESHREE KHANDE
LayoutManager Classes :BorderLayout
 Frame is divided into north, south, east, west, and
center
 Components are placed by the programmer in the
desired location using the add method
14RAJESHREE KHANDE
15RAJESHREE KHANDE
LayoutManager Classes :BorderLayout
Following are constructor for BorderLayout
1) BorderLayout()
2) BorderLayout(int hspace, int vspace)
To add a component in BorderLayout use following
format of add() method
Syntax :
void add(Component-obj, Object Region)
16RAJESHREE KHANDE
LayoutManager Classes :BorderLayout
 Where region specifies following five
constant:
1. BorderLayout.EAST
2. BorderLayout.WEST
3. BorderLayout.SOUTH
4. BorderLayout.NORTH
5. BorderLayout.CENTER
Example
17RAJESHREE KHANDE
LayoutManager Classes
:GridLayout
2.GridLayout
 Frame is declared as a grid of fixed size
(e.g. two rows and three columns)
 Components are placed in the grid left to
right and top to bottom
18RAJESHREE KHANDE
LayoutManager Classes
:GridLayout
 GridLayout uses following Constructor
1) GridLayout()
Creates a single column grid Layout
2) GridLayout(int nrows, int ncols)
Creates a grid layout with specified no. of rows and
columns
3) GridLayout(int nrows, int ncols, int hspcae, int vspace)
Creates a grid layout with specified no. of rows and
columns and specifies horizontal and vertical space
between the component
19RAJESHREE KHANDE
LayoutManager Classes
:GridLayout
 Example1
 Example1
20RAJESHREE KHANDE
AWT Component
Adding a control
1. Create an instance of desired control
2. Then add it to window by calling add() method which is define by
container
3. The add method has several form
4. Once the control has been added it will be automatically visible
whenever it’s parent window is display
Syntax
Component add(Component compObj)
21RAJESHREE KHANDE
AWT Component
Removing a control
 If control no longer need we will remove that control
by remove() method
 This method also defined by Container class
Syntax
void remove (Component compObj)
 We can remove all controls by removeAll() method
22RAJESHREE KHANDE
AWT Component
Responding to controls
1. All control except label generates events when they
are accessed by user.
2. In general , your program simply implements the
appropriate interface & register an event listener
for each control that need to monitor.
23RAJESHREE KHANDE
AWT Component
Label
1. It is an object type Label
2. It is a passive control
3. Do not support any interaction
Following Constructor
1. Label() : Construct blank label
2. Label(String) : construct a label containing string
3. Label(String, int) :
Alignment
( Label.LEFT,Label.RIGHT,
Label.CENTER) 24RAJESHREE KHANDE
AWT Component :Label
 Methods
Sr.
No
Methods Description
1 void setText(String) Set or change a text of label
2 String getText() Obtain the text of label
3 void setAlignment(int) Set or change the alignment
of text in the label
4 int getAlignment() Obtain the current alignment
25RAJESHREE KHANDE
AWT Component :Push Button
1. It is push button component
2. Contain a label
3. Generate a event when it is pressed
4. It is an object of type Button
5. Button defines two constructor
1. Button() : Create a buttton without label
2. Button (String str) :Creates a button with label
26RAJESHREE KHANDE
 Methods
Sr.
No
Methods Description
1 void setLabel(String) Set or change a label of
Button
2 String getLabel() Obtain the label Button
AWT Component :Push Button
27RAJESHREE KHANDE
AWT Component :TextField
 TextField class is used to create a single line text
entry edit box.
 Constructor
1. TextField() : Creates a default textfield
2. TextField(int) : Creates a textfield which wide as
specified number of characters.
3. Textfield(String) : Creates a textfield with specified
string initially.
4. TextField(String, int) : Creates a textfield with initial
text and set it’s width.
28RAJESHREE KHANDE
AWT Component :TextField
 Methods
Sr.
No
Methods Description
1 String getText() Return the content of TextField.
2 void setText(String) Set or change the text of TextField.
3 String getSelectedText() To get currently selected text
4 void select(int startIndex, int
endIndex)
To select portion of text
5 boolean isEditable() To determine editability
6 void setEditable(boolean) To set or reset editability 29RAJESHREE KHANDE
AWT Component :TextField
 Example1 :Button and Label
 Example2 : Conversion to binary ,Hexadecimal, Octal
 Example 3: Converting String to Uppercase and
Lowercase
30RAJESHREE KHANDE
AWT Component :Check Box
 Used to toggle an option
 A Checkbox class is used to create an object
 Constructor
1. Checkbox() :
Creates a checkbox without label.
2. Checkbox(String) :
Creates a checkbox with label specified initial state is
unchecked.
3 Checkbox(String, boolean) :
Creates a checkbox with label specified initial state is
either true or false.
31RAJESHREE KHANDE
AWT Component :Check Box
 Methods
Sr.
No
Methods Description
1 Boolean getState() Retrieve the current state
2 void setState(boolean) Set the state true or false
3 String getLabel() Retrieve the label associated
4 Void setLabel(String) Sets the label as specified
32RAJESHREE KHANDE
AWT Component :CheckBoxGroup
 It is also called radio buttons
 CheckBoxGroup class is used to create group of
check boxes.
 From list of choices we select only one at a time.
 Constructor
CheckboxGroup()
e.g.
CheckBoxGroup cbg = new CheckBoxGroup()
c1 = new Checkbox("check-1“,cbg,true);
c2 = new Checkbox("check-2“,cbg,false);
c3 = new Checkbox("check-3“,cbg,false);
33RAJESHREE KHANDE
AWT Component :CheckBoxGroup
Method :
1)getSelectedCheckbox() : determine which
checkbox in a group is currently selected
Checkbox getSelectedCheckbox()
2)setSelectedCheckbox() : set a check box
void setSelectedCheckbox(Checkbox obj))
34RAJESHREE KHANDE
AWT Component :List
 Provide a list of items, which can be scrolled
 From list of items single or multiple item can be
selected.
 Constructor
1. List() : Creates a listbox in which single selection is
possible.
2. List(int) :Creates a listbox , specified number of
items always to visible selection.
Selection is possible
35RAJESHREE KHANDE
AWT Component :List
3. List(int, boolean) :
Specified no. of items
To be visible
Specifies wheather
multiple selection is
allowed
True Indicate multiple
Selection
36RAJESHREE KHANDE
AWT Component :List
Sr.
No
Methods Description
1 Void add(string) Add item to the end of list
2 Void add(String,int) Add the item at the index specified
in second parameter.
3 String getSelectedItem() Returns a string which is selected
4 int getSelectedIndex() Return an index of selected item
5 String[] getSelectedItems() Returns an array contains string
which are selected.(Multiselect)
37RAJESHREE KHANDE
AWT Component :List
Sr.
No
Methods Description
6 Int[] getSelectedIndexes() Returns an array containing
indexes of selected items.
7 Int getItemCount() Returns no. of items in the list
8 Void select(int) Select the item of specified index
9 String getItem(int) Obtain the name of item having
specified index.
38RAJESHREE KHANDE
AWT Component :List
 Example1
 Example2
39RAJESHREE KHANDE
AWT Component :Choice list
 The class Choice is used to create a drop-down or
pop-up list of string
 It requires less space than the list box control
 It uses only default constructor
Choice()
40RAJESHREE KHANDE
AWT Component :Choice list
Sr.
No
Methods Description
1 void add(String) To add a string in choice list
2 String getSelectedItem() Determine which item is currently selected
3 int getSelectedIndex() Determine the index of currently selected
item.
4 int getItemCount() Returns no. of items in the list
5 void select(int) Select the item whose index is specified
6 void select(String) Select the item match with string parameter
7 String getItem(int) Obtain the name associated with the item at
specified index
41RAJESHREE KHANDE
AWT Component :Choice list
 Example of Choice list
42RAJESHREE KHANDE
AWT Component :TextArea
 TextArea class is used to create a multiline textbox
Following constructor are available
1. TextArea() :
Creates a default TextArea
2. TextArea(int, int) :
Creates a TextArea with specified no. of lines &
characters.
43RAJESHREE KHANDE
AWT Component :TextArea
3. TextArea(String) :
Create with initial string.
4. TextArea(Sring, int, int) :
Creates a TextArea with initial string and for
specified no. of lines & characters.
5. TextArea(String, int numlines, int nchar, int s bars)
Creates a TextArea with Scroll Bars. The value of
sBars must be one of the following
SCROLLBAR_BOTH, SCROLLBAR_NONE,
SCROLLBAR_HORIZONTAL_ONLY,
SCROLLBAR_VERTICAL_ONLY
44RAJESHREE KHANDE
AWT Component :TextArea
 Support all the methods of TextField & some
additional method
Sr.
No
Methods Description
1 void append(String) Append Specified string at the
end.
2 void insert(string,int) Insert a string at specified index
3 void replace(String, int
startIndex, endIndex)
It replaces the character from
start index to end with given
string
45RAJESHREE KHANDE
AWT Component :Scroll Bars
 Scrollbar class is used to create scrollbar.
 Scrollbar may be either vertical or horizontal.
 Constructor
1. Scrollbar() :
Create vertical scrollbar.
2. Scrollbar(int style) :
Create a scrollbar of specified style. It can be
Scrollbar.HORIZONTAL
Scrollbar.VERTICAL
46RAJESHREE KHANDE
AWT Component :Scrollbar
3. Scrollbar(int style, int start, int thumb,int min, int max) :
Create a scrollbar with specified style.
Initial Value Thumbsize
47RAJESHREE KHANDE
AWT Component :Scrollbar
Sr.
No
Methods Description
1 int getValue() To get the current value of scroll bar
2 void setValue(int) Set new value
3 int getMinimum() To get minimum value of scrollbar
4 int getMaximum() To get maximum value of scrollbar
5 void setUnitIncrement(int) To change unit increment.
Default is 1
6 void setBlockIncrement(int) To change block increment.
Default is 10
48RAJESHREE KHANDE
Graphics
 AWT support a rich assortment of Graphics methods.
 All graphics are drawn relative to window.
 This can be main window of an applet, Child window
of an applet or stand alone application window
 The origin of window is at the Top-left corner and is
(0,0).
 Co-ordinates is specified in pixel.
 All output to a window takes place through a
graphics context.
49RAJESHREE KHANDE
Graphics
 Graphics Context is encapsulated by Graphics class &
is obtained in two ways.
1. It is passed to an applet when one of it’s various
methods, such as paint() or update() .
2. It is returned by getGraphics() method of Component
 The Graphics class defines the a number of
drawing functions
 Each shape can be drawn edge-only or filled
50RAJESHREE KHANDE
Graphics
 Object are drawn and filled in currently selected
graphics color, which is black by default.
 When a graphics object is drawn that exceeds the
dimension of the window, output is automatically
clipped
51RAJESHREE KHANDE
Drawing Lines
 Lines are drawn by means of the drawLine() method
void drawLine(int startX, int startY,int endX, endY)
drawLine() display a line in the current drawing
color.
Example
52RAJESHREE KHANDE
Drawing Rectangle
 drawRect() method display an outline of rectangle
 fillRect() method filled the rectangle.
void drawRect(int top,int left,int width, int height)
void fillRect(int top, int left, int width, int height)
 The upper-left corner of the rectangle is top,left
 The dimension of the rectangle are specified by
width and height.
53RAJESHREE KHANDE
Drawing Rounded Rectangle
 To draw Rounded Rectangle use drawRoundRect() of
fillRoundRect().
void drawRect(int top,int left,int width, int height)
void fillRect(int top, int left, int width, int height)
54RAJESHREE KHANDE
LayoutManager Classes
:CardLayout
 CardLayout
-- Display containers you pass to it as card.
-- You give each card a name.
-- The card are typically held in an object of type Panel
-- We can move from card to card with the Card’s
layout show() method.
--We can also display specific cards using first , last, next & previous
method of CardLayout.
55RAJESHREE KHANDE
 is encapsulated by graphics class & is obtained in two
ways.
56RAJESHREE KHANDE
LayoutManager Classes
:CardLayout
 Constructor
1) CardLayout() :
creates new card layout
2) CardLayout(int hspace,int vspace)
creates new card layout with given horizontal and
vertical space
57RAJESHREE KHANDE
LayoutManager Classes
:CardLayout
Step for CardLayout
1. Create a panel that contains a deck and panel for each card
in the deck.
2. Add to the appropriate panel the components that form
each card.
3. Then add these panels to the panel for which CardLayout is
the layout manager
4. Finally you add this panel to window
5. To select between the cards ,include one push button for
each card in the deck.
58RAJESHREE KHANDE
LayoutManager Classes
:CardLayout
 When panels are added to panel, they are given a name.
So use the following add method
Void add(Component panelObj, Object name)
Name of the card whose
panel is specified by
panelObj
59RAJESHREE KHANDE
LayoutManager Classes
:CardLayout
 After deck creation, you can activate a card by
calling one of the method defined by CardLayout
1. void first(Container deck)
2. void last(Container deck)
3. void next(Container deck)
4. void previous(Container deck)
5. void show(Container deck,String cardName) 60RAJESHREE KHANDE
LayoutManager Classes
:CardLayout
 deck : is the reference to the container(usually panel)
that holds the card
 cardName : is the name of the card
 Example
61RAJESHREE KHANDE
Scrollbars
 The leftmost position of a horizontal scrollbar
corresponds to some integer value and the rightmost
position corresponds to a larger integer value
 Scrollbars can be displayed vertically
 User movement options
 Clicking either end button causes bubble to move in
unit increments.
 Clicking the are between bubble and end button
causes movement in 10 unit increments
 Clicking and dragging the bubble in the desired
direction
62RAJESHREE KHANDE
Using Inheritance
 It is possible to use inheritance to allow
TwoButtons to become a frame in its own
right
 Note that the UML diagram will show
TwoButtons as a subclass of Frame
 You will need to use super()to set the
frame title
63RAJESHREE KHANDE

More Related Content

What's hot (20)

Java Swing
Java SwingJava Swing
Java Swing
 
Files in java
Files in javaFiles in java
Files in java
 
Multithreading In Java
Multithreading In JavaMultithreading In Java
Multithreading In Java
 
String and string buffer
String and string bufferString and string buffer
String and string buffer
 
Core java complete ppt(note)
Core java  complete  ppt(note)Core java  complete  ppt(note)
Core java complete ppt(note)
 
Java collections concept
Java collections conceptJava collections concept
Java collections concept
 
Ado.Net Tutorial
Ado.Net TutorialAdo.Net Tutorial
Ado.Net Tutorial
 
enterprise java bean
enterprise java beanenterprise java bean
enterprise java bean
 
Java Beans
Java BeansJava Beans
Java Beans
 
servlet in java
servlet in javaservlet in java
servlet in java
 
Threads in JAVA
Threads in JAVAThreads in JAVA
Threads in JAVA
 
Asp.NET Validation controls
Asp.NET Validation controlsAsp.NET Validation controls
Asp.NET Validation controls
 
Event handling
Event handlingEvent handling
Event handling
 
JDBC: java DataBase connectivity
JDBC: java DataBase connectivityJDBC: java DataBase connectivity
JDBC: java DataBase connectivity
 
Servlet and servlet life cycle
Servlet and servlet life cycleServlet and servlet life cycle
Servlet and servlet life cycle
 
Hibernate ppt
Hibernate pptHibernate ppt
Hibernate ppt
 
Event Handling in java
Event Handling in javaEvent Handling in java
Event Handling in java
 
Java I/o streams
Java I/o streamsJava I/o streams
Java I/o streams
 
Java Collections
Java  Collections Java  Collections
Java Collections
 
String Builder & String Buffer (Java Programming)
String Builder & String Buffer (Java Programming)String Builder & String Buffer (Java Programming)
String Builder & String Buffer (Java Programming)
 

Similar to Dr. Rajeshree Khande :Introduction to Java AWT

Similar to Dr. Rajeshree Khande :Introduction to Java AWT (20)

Unit-1 awt advanced java programming
Unit-1 awt advanced java programmingUnit-1 awt advanced java programming
Unit-1 awt advanced java programming
 
Windows Programming with AWT
Windows Programming with AWTWindows Programming with AWT
Windows Programming with AWT
 
Abstract Window Toolkit
Abstract Window ToolkitAbstract Window Toolkit
Abstract Window Toolkit
 
Ajp notes-chapter-01
Ajp notes-chapter-01Ajp notes-chapter-01
Ajp notes-chapter-01
 
awt controls .pptx
awt controls .pptxawt controls .pptx
awt controls .pptx
 
B.Sc. III(VI Sem) Advance Java Unit3: AWT & Event Handling
B.Sc. III(VI Sem) Advance Java Unit3: AWT & Event HandlingB.Sc. III(VI Sem) Advance Java Unit3: AWT & Event Handling
B.Sc. III(VI Sem) Advance Java Unit3: AWT & Event Handling
 
Ajp notes-chapter-01
Ajp notes-chapter-01Ajp notes-chapter-01
Ajp notes-chapter-01
 
Chap1 1.4
Chap1 1.4Chap1 1.4
Chap1 1.4
 
3_ppt_Layout.pptxgßbdbdbdbsbsbsbbsbsbsbsbsb
3_ppt_Layout.pptxgßbdbdbdbsbsbsbbsbsbsbsbsb3_ppt_Layout.pptxgßbdbdbdbsbsbsbbsbsbsbsbsb
3_ppt_Layout.pptxgßbdbdbdbsbsbsbbsbsbsbsbsb
 
java swing
java swingjava swing
java swing
 
java
javajava
java
 
Chap1 1 4
Chap1 1 4Chap1 1 4
Chap1 1 4
 
Java swing
Java swingJava swing
Java swing
 
Implement a Javascript application that allows the user to enter strin.docx
Implement a Javascript application that allows the user to enter strin.docxImplement a Javascript application that allows the user to enter strin.docx
Implement a Javascript application that allows the user to enter strin.docx
 
Graphical User Interface in JAVA
Graphical User Interface in JAVAGraphical User Interface in JAVA
Graphical User Interface in JAVA
 
17625-1.pptx
17625-1.pptx17625-1.pptx
17625-1.pptx
 
Labels and buttons
Labels and buttonsLabels and buttons
Labels and buttons
 
Unit 5 java-awt (1)
Unit 5 java-awt (1)Unit 5 java-awt (1)
Unit 5 java-awt (1)
 
UNIT-2-AJAVA.pdf
UNIT-2-AJAVA.pdfUNIT-2-AJAVA.pdf
UNIT-2-AJAVA.pdf
 
GUI components in Java
GUI components in JavaGUI components in Java
GUI components in Java
 

More from DrRajeshreeKhande

More from DrRajeshreeKhande (20)

.NET F# Inheritance and operator overloading
.NET F# Inheritance and operator overloading.NET F# Inheritance and operator overloading
.NET F# Inheritance and operator overloading
 
Exception Handling in .NET F#
Exception Handling in .NET F#Exception Handling in .NET F#
Exception Handling in .NET F#
 
.NET F# Events
.NET F# Events.NET F# Events
.NET F# Events
 
.NET F# Class constructor
.NET F# Class constructor.NET F# Class constructor
.NET F# Class constructor
 
.NET F# Abstract class interface
.NET F# Abstract class interface.NET F# Abstract class interface
.NET F# Abstract class interface
 
.Net F# Generic class
.Net F# Generic class.Net F# Generic class
.Net F# Generic class
 
F# Console class
F# Console classF# Console class
F# Console class
 
.net F# mutable dictionay
.net F# mutable dictionay.net F# mutable dictionay
.net F# mutable dictionay
 
F sharp lists & dictionary
F sharp   lists &  dictionaryF sharp   lists &  dictionary
F sharp lists & dictionary
 
F# array searching
F#  array searchingF#  array searching
F# array searching
 
Net (f#) array
Net (f#)  arrayNet (f#)  array
Net (f#) array
 
.Net (F # ) Records, lists
.Net (F # ) Records, lists.Net (F # ) Records, lists
.Net (F # ) Records, lists
 
MS Office for Beginners
MS Office for BeginnersMS Office for Beginners
MS Office for Beginners
 
Java Multi-threading programming
Java Multi-threading programmingJava Multi-threading programming
Java Multi-threading programming
 
Java String class
Java String classJava String class
Java String class
 
JAVA AWT components
JAVA AWT componentsJAVA AWT components
JAVA AWT components
 
Dr. Rajeshree Khande Java Interactive input
Dr. Rajeshree Khande Java Interactive inputDr. Rajeshree Khande Java Interactive input
Dr. Rajeshree Khande Java Interactive input
 
Dr. Rajeshree Khande :Intoduction to java
Dr. Rajeshree Khande :Intoduction to javaDr. Rajeshree Khande :Intoduction to java
Dr. Rajeshree Khande :Intoduction to java
 
Java Exceptions Handling
Java Exceptions Handling Java Exceptions Handling
Java Exceptions Handling
 
Dr. Rajeshree Khande : Java Basics
Dr. Rajeshree Khande  : Java BasicsDr. Rajeshree Khande  : Java Basics
Dr. Rajeshree Khande : Java Basics
 

Recently uploaded

Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxEyham Joco
 
Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Celine George
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
ACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfSpandanaRallapalli
 
Grade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptxGrade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptxChelloAnnAsuncion2
 
Gas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxGas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxDr.Ibrahim Hassaan
 
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...Nguyen Thanh Tu Collection
 
ROOT CAUSE ANALYSIS PowerPoint Presentation
ROOT CAUSE ANALYSIS PowerPoint PresentationROOT CAUSE ANALYSIS PowerPoint Presentation
ROOT CAUSE ANALYSIS PowerPoint PresentationAadityaSharma884161
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...JhezDiaz1
 
Planning a health career 4th Quarter.pptx
Planning a health career 4th Quarter.pptxPlanning a health career 4th Quarter.pptx
Planning a health career 4th Quarter.pptxLigayaBacuel1
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxAnupkumar Sharma
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPCeline George
 
Romantic Opera MUSIC FOR GRADE NINE pptx
Romantic Opera MUSIC FOR GRADE NINE pptxRomantic Opera MUSIC FOR GRADE NINE pptx
Romantic Opera MUSIC FOR GRADE NINE pptxsqpmdrvczh
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatYousafMalik24
 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Jisc
 

Recently uploaded (20)

Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptx
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
ACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdf
 
Grade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptxGrade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptx
 
Gas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxGas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptx
 
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
 
ROOT CAUSE ANALYSIS PowerPoint Presentation
ROOT CAUSE ANALYSIS PowerPoint PresentationROOT CAUSE ANALYSIS PowerPoint Presentation
ROOT CAUSE ANALYSIS PowerPoint Presentation
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
 
Planning a health career 4th Quarter.pptx
Planning a health career 4th Quarter.pptxPlanning a health career 4th Quarter.pptx
Planning a health career 4th Quarter.pptx
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERP
 
Romantic Opera MUSIC FOR GRADE NINE pptx
Romantic Opera MUSIC FOR GRADE NINE pptxRomantic Opera MUSIC FOR GRADE NINE pptx
Romantic Opera MUSIC FOR GRADE NINE pptx
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice great
 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...
 

Dr. Rajeshree Khande :Introduction to Java AWT

  • 1. AWT :Abstract Window ToolKit  AWT is collection of classes and methods that allows to create & manage window.  AWT provide support for Applet.  AWT contains support for windows_ based Graphical Interface.  To use the AWT classes & method we have to import awt package as import java.awt.*; 1RAJESHREE KHANDE
  • 2. AWT:classes  Different window classes are defined by AWT which add functionality with each level. Component Container Window Panel Frame Applet 2RAJESHREE KHANDE
  • 4. AWT:classes  Component :  It’ an abstract class.  All GUI component that interact with user are subclasses of component class.  Defines various methods for managing event such as keyboard & mouse input.  Also defines attribute to store current foreground & background colors and fonts 4RAJESHREE KHANDE
  • 5. AWT:classes  Container:  Inherits various methods & attribute of component class  Having additional methods of nesting other component object.  A container position various GUI component within it with the help of different Layout manager 5RAJESHREE KHANDE
  • 6. AWT:classes  Panel :  It is a window which does not contain title bar, menu bar, border.  It is super class of Applet class.  Any screen output written on applet is drawn on the surface of panel object.  AppletViewer provide titlebar & border to an applet.  We add GUI component such as buttons ,list box to a panel. 6RAJESHREE KHANDE
  • 7. AWT:classes  Window :  Window class is used to create top level window.  Window object are not created directly.  Subclass of window is used to place on desktop. 7RAJESHREE KHANDE
  • 8. AWT:classes  Frame:  It is subclass of window.  It has title bar , menu bar & border etc  To create a normal window in Java application Frame class is used.  In Applet we does not use Frame class, since AppletViewer provide titlebar, menubar & boarder to an applet. 8RAJESHREE KHANDE
  • 9. AWT:classes  Canvas:  It is not subclass of window or panel.  It is another type of window.  This widow is blank window upon which we can draw. 9RAJESHREE KHANDE
  • 10. Layout Managers  It is an object which determine the way that component are arranged in frame window.  It arranges a control within a window using some type of an algorithm.  Each window has a layout manager associated with it. 10RAJESHREE KHANDE
  • 11. Layout Managers  LayoutManager is set by the setLayout() method to a window. syntax void setLayout(LayoutManager layobj)  If it is not set then default layout manager is used  If layobj parameter set to null then control are positioned manually using the setBound() method 11RAJESHREE KHANDE
  • 12. LayoutManager Classes 1.FlowLayout  Default frame layout.  Places Components in successive rows in window fitting as many as in each row as possible.  When the row is full it start fitting the components on the next row.  This is similar to how word flow in text editor  A small space is left in each component. 12RAJESHREE KHANDE
  • 13. LayoutManager Classes :FlowLayout  Following are constructor for FlowLayout. 1. FlowLayout() Centers all component and leves 5 pixel space between each component 2. FlowLayout(int align) Flowlayout.LEFT Flowlayout.CENTER Flowlayout.RIGHT Flowlayout.LEADING Flowlayout.TRAILING 3. FlowLayout(int align, int hspace, int vspace)  Example 13RAJESHREE KHANDE
  • 14. LayoutManager Classes :BorderLayout  Frame is divided into north, south, east, west, and center  Components are placed by the programmer in the desired location using the add method 14RAJESHREE KHANDE
  • 16. LayoutManager Classes :BorderLayout Following are constructor for BorderLayout 1) BorderLayout() 2) BorderLayout(int hspace, int vspace) To add a component in BorderLayout use following format of add() method Syntax : void add(Component-obj, Object Region) 16RAJESHREE KHANDE
  • 17. LayoutManager Classes :BorderLayout  Where region specifies following five constant: 1. BorderLayout.EAST 2. BorderLayout.WEST 3. BorderLayout.SOUTH 4. BorderLayout.NORTH 5. BorderLayout.CENTER Example 17RAJESHREE KHANDE
  • 18. LayoutManager Classes :GridLayout 2.GridLayout  Frame is declared as a grid of fixed size (e.g. two rows and three columns)  Components are placed in the grid left to right and top to bottom 18RAJESHREE KHANDE
  • 19. LayoutManager Classes :GridLayout  GridLayout uses following Constructor 1) GridLayout() Creates a single column grid Layout 2) GridLayout(int nrows, int ncols) Creates a grid layout with specified no. of rows and columns 3) GridLayout(int nrows, int ncols, int hspcae, int vspace) Creates a grid layout with specified no. of rows and columns and specifies horizontal and vertical space between the component 19RAJESHREE KHANDE
  • 21. AWT Component Adding a control 1. Create an instance of desired control 2. Then add it to window by calling add() method which is define by container 3. The add method has several form 4. Once the control has been added it will be automatically visible whenever it’s parent window is display Syntax Component add(Component compObj) 21RAJESHREE KHANDE
  • 22. AWT Component Removing a control  If control no longer need we will remove that control by remove() method  This method also defined by Container class Syntax void remove (Component compObj)  We can remove all controls by removeAll() method 22RAJESHREE KHANDE
  • 23. AWT Component Responding to controls 1. All control except label generates events when they are accessed by user. 2. In general , your program simply implements the appropriate interface & register an event listener for each control that need to monitor. 23RAJESHREE KHANDE
  • 24. AWT Component Label 1. It is an object type Label 2. It is a passive control 3. Do not support any interaction Following Constructor 1. Label() : Construct blank label 2. Label(String) : construct a label containing string 3. Label(String, int) : Alignment ( Label.LEFT,Label.RIGHT, Label.CENTER) 24RAJESHREE KHANDE
  • 25. AWT Component :Label  Methods Sr. No Methods Description 1 void setText(String) Set or change a text of label 2 String getText() Obtain the text of label 3 void setAlignment(int) Set or change the alignment of text in the label 4 int getAlignment() Obtain the current alignment 25RAJESHREE KHANDE
  • 26. AWT Component :Push Button 1. It is push button component 2. Contain a label 3. Generate a event when it is pressed 4. It is an object of type Button 5. Button defines two constructor 1. Button() : Create a buttton without label 2. Button (String str) :Creates a button with label 26RAJESHREE KHANDE
  • 27.  Methods Sr. No Methods Description 1 void setLabel(String) Set or change a label of Button 2 String getLabel() Obtain the label Button AWT Component :Push Button 27RAJESHREE KHANDE
  • 28. AWT Component :TextField  TextField class is used to create a single line text entry edit box.  Constructor 1. TextField() : Creates a default textfield 2. TextField(int) : Creates a textfield which wide as specified number of characters. 3. Textfield(String) : Creates a textfield with specified string initially. 4. TextField(String, int) : Creates a textfield with initial text and set it’s width. 28RAJESHREE KHANDE
  • 29. AWT Component :TextField  Methods Sr. No Methods Description 1 String getText() Return the content of TextField. 2 void setText(String) Set or change the text of TextField. 3 String getSelectedText() To get currently selected text 4 void select(int startIndex, int endIndex) To select portion of text 5 boolean isEditable() To determine editability 6 void setEditable(boolean) To set or reset editability 29RAJESHREE KHANDE
  • 30. AWT Component :TextField  Example1 :Button and Label  Example2 : Conversion to binary ,Hexadecimal, Octal  Example 3: Converting String to Uppercase and Lowercase 30RAJESHREE KHANDE
  • 31. AWT Component :Check Box  Used to toggle an option  A Checkbox class is used to create an object  Constructor 1. Checkbox() : Creates a checkbox without label. 2. Checkbox(String) : Creates a checkbox with label specified initial state is unchecked. 3 Checkbox(String, boolean) : Creates a checkbox with label specified initial state is either true or false. 31RAJESHREE KHANDE
  • 32. AWT Component :Check Box  Methods Sr. No Methods Description 1 Boolean getState() Retrieve the current state 2 void setState(boolean) Set the state true or false 3 String getLabel() Retrieve the label associated 4 Void setLabel(String) Sets the label as specified 32RAJESHREE KHANDE
  • 33. AWT Component :CheckBoxGroup  It is also called radio buttons  CheckBoxGroup class is used to create group of check boxes.  From list of choices we select only one at a time.  Constructor CheckboxGroup() e.g. CheckBoxGroup cbg = new CheckBoxGroup() c1 = new Checkbox("check-1“,cbg,true); c2 = new Checkbox("check-2“,cbg,false); c3 = new Checkbox("check-3“,cbg,false); 33RAJESHREE KHANDE
  • 34. AWT Component :CheckBoxGroup Method : 1)getSelectedCheckbox() : determine which checkbox in a group is currently selected Checkbox getSelectedCheckbox() 2)setSelectedCheckbox() : set a check box void setSelectedCheckbox(Checkbox obj)) 34RAJESHREE KHANDE
  • 35. AWT Component :List  Provide a list of items, which can be scrolled  From list of items single or multiple item can be selected.  Constructor 1. List() : Creates a listbox in which single selection is possible. 2. List(int) :Creates a listbox , specified number of items always to visible selection. Selection is possible 35RAJESHREE KHANDE
  • 36. AWT Component :List 3. List(int, boolean) : Specified no. of items To be visible Specifies wheather multiple selection is allowed True Indicate multiple Selection 36RAJESHREE KHANDE
  • 37. AWT Component :List Sr. No Methods Description 1 Void add(string) Add item to the end of list 2 Void add(String,int) Add the item at the index specified in second parameter. 3 String getSelectedItem() Returns a string which is selected 4 int getSelectedIndex() Return an index of selected item 5 String[] getSelectedItems() Returns an array contains string which are selected.(Multiselect) 37RAJESHREE KHANDE
  • 38. AWT Component :List Sr. No Methods Description 6 Int[] getSelectedIndexes() Returns an array containing indexes of selected items. 7 Int getItemCount() Returns no. of items in the list 8 Void select(int) Select the item of specified index 9 String getItem(int) Obtain the name of item having specified index. 38RAJESHREE KHANDE
  • 39. AWT Component :List  Example1  Example2 39RAJESHREE KHANDE
  • 40. AWT Component :Choice list  The class Choice is used to create a drop-down or pop-up list of string  It requires less space than the list box control  It uses only default constructor Choice() 40RAJESHREE KHANDE
  • 41. AWT Component :Choice list Sr. No Methods Description 1 void add(String) To add a string in choice list 2 String getSelectedItem() Determine which item is currently selected 3 int getSelectedIndex() Determine the index of currently selected item. 4 int getItemCount() Returns no. of items in the list 5 void select(int) Select the item whose index is specified 6 void select(String) Select the item match with string parameter 7 String getItem(int) Obtain the name associated with the item at specified index 41RAJESHREE KHANDE
  • 42. AWT Component :Choice list  Example of Choice list 42RAJESHREE KHANDE
  • 43. AWT Component :TextArea  TextArea class is used to create a multiline textbox Following constructor are available 1. TextArea() : Creates a default TextArea 2. TextArea(int, int) : Creates a TextArea with specified no. of lines & characters. 43RAJESHREE KHANDE
  • 44. AWT Component :TextArea 3. TextArea(String) : Create with initial string. 4. TextArea(Sring, int, int) : Creates a TextArea with initial string and for specified no. of lines & characters. 5. TextArea(String, int numlines, int nchar, int s bars) Creates a TextArea with Scroll Bars. The value of sBars must be one of the following SCROLLBAR_BOTH, SCROLLBAR_NONE, SCROLLBAR_HORIZONTAL_ONLY, SCROLLBAR_VERTICAL_ONLY 44RAJESHREE KHANDE
  • 45. AWT Component :TextArea  Support all the methods of TextField & some additional method Sr. No Methods Description 1 void append(String) Append Specified string at the end. 2 void insert(string,int) Insert a string at specified index 3 void replace(String, int startIndex, endIndex) It replaces the character from start index to end with given string 45RAJESHREE KHANDE
  • 46. AWT Component :Scroll Bars  Scrollbar class is used to create scrollbar.  Scrollbar may be either vertical or horizontal.  Constructor 1. Scrollbar() : Create vertical scrollbar. 2. Scrollbar(int style) : Create a scrollbar of specified style. It can be Scrollbar.HORIZONTAL Scrollbar.VERTICAL 46RAJESHREE KHANDE
  • 47. AWT Component :Scrollbar 3. Scrollbar(int style, int start, int thumb,int min, int max) : Create a scrollbar with specified style. Initial Value Thumbsize 47RAJESHREE KHANDE
  • 48. AWT Component :Scrollbar Sr. No Methods Description 1 int getValue() To get the current value of scroll bar 2 void setValue(int) Set new value 3 int getMinimum() To get minimum value of scrollbar 4 int getMaximum() To get maximum value of scrollbar 5 void setUnitIncrement(int) To change unit increment. Default is 1 6 void setBlockIncrement(int) To change block increment. Default is 10 48RAJESHREE KHANDE
  • 49. Graphics  AWT support a rich assortment of Graphics methods.  All graphics are drawn relative to window.  This can be main window of an applet, Child window of an applet or stand alone application window  The origin of window is at the Top-left corner and is (0,0).  Co-ordinates is specified in pixel.  All output to a window takes place through a graphics context. 49RAJESHREE KHANDE
  • 50. Graphics  Graphics Context is encapsulated by Graphics class & is obtained in two ways. 1. It is passed to an applet when one of it’s various methods, such as paint() or update() . 2. It is returned by getGraphics() method of Component  The Graphics class defines the a number of drawing functions  Each shape can be drawn edge-only or filled 50RAJESHREE KHANDE
  • 51. Graphics  Object are drawn and filled in currently selected graphics color, which is black by default.  When a graphics object is drawn that exceeds the dimension of the window, output is automatically clipped 51RAJESHREE KHANDE
  • 52. Drawing Lines  Lines are drawn by means of the drawLine() method void drawLine(int startX, int startY,int endX, endY) drawLine() display a line in the current drawing color. Example 52RAJESHREE KHANDE
  • 53. Drawing Rectangle  drawRect() method display an outline of rectangle  fillRect() method filled the rectangle. void drawRect(int top,int left,int width, int height) void fillRect(int top, int left, int width, int height)  The upper-left corner of the rectangle is top,left  The dimension of the rectangle are specified by width and height. 53RAJESHREE KHANDE
  • 54. Drawing Rounded Rectangle  To draw Rounded Rectangle use drawRoundRect() of fillRoundRect(). void drawRect(int top,int left,int width, int height) void fillRect(int top, int left, int width, int height) 54RAJESHREE KHANDE
  • 55. LayoutManager Classes :CardLayout  CardLayout -- Display containers you pass to it as card. -- You give each card a name. -- The card are typically held in an object of type Panel -- We can move from card to card with the Card’s layout show() method. --We can also display specific cards using first , last, next & previous method of CardLayout. 55RAJESHREE KHANDE
  • 56.  is encapsulated by graphics class & is obtained in two ways. 56RAJESHREE KHANDE
  • 57. LayoutManager Classes :CardLayout  Constructor 1) CardLayout() : creates new card layout 2) CardLayout(int hspace,int vspace) creates new card layout with given horizontal and vertical space 57RAJESHREE KHANDE
  • 58. LayoutManager Classes :CardLayout Step for CardLayout 1. Create a panel that contains a deck and panel for each card in the deck. 2. Add to the appropriate panel the components that form each card. 3. Then add these panels to the panel for which CardLayout is the layout manager 4. Finally you add this panel to window 5. To select between the cards ,include one push button for each card in the deck. 58RAJESHREE KHANDE
  • 59. LayoutManager Classes :CardLayout  When panels are added to panel, they are given a name. So use the following add method Void add(Component panelObj, Object name) Name of the card whose panel is specified by panelObj 59RAJESHREE KHANDE
  • 60. LayoutManager Classes :CardLayout  After deck creation, you can activate a card by calling one of the method defined by CardLayout 1. void first(Container deck) 2. void last(Container deck) 3. void next(Container deck) 4. void previous(Container deck) 5. void show(Container deck,String cardName) 60RAJESHREE KHANDE
  • 61. LayoutManager Classes :CardLayout  deck : is the reference to the container(usually panel) that holds the card  cardName : is the name of the card  Example 61RAJESHREE KHANDE
  • 62. Scrollbars  The leftmost position of a horizontal scrollbar corresponds to some integer value and the rightmost position corresponds to a larger integer value  Scrollbars can be displayed vertically  User movement options  Clicking either end button causes bubble to move in unit increments.  Clicking the are between bubble and end button causes movement in 10 unit increments  Clicking and dragging the bubble in the desired direction 62RAJESHREE KHANDE
  • 63. Using Inheritance  It is possible to use inheritance to allow TwoButtons to become a frame in its own right  Note that the UML diagram will show TwoButtons as a subclass of Frame  You will need to use super()to set the frame title 63RAJESHREE KHANDE