2. Objective
On completion of this period, you would be
able to know
• Working with Frames
http://improvejava.blogspot.in/
2
3. Recap
In the previous class, you have leant
• Fundamentals of Windows
• Frame, Panel class hierarchy
http://improvejava.blogspot.in/
3
4. Working with Frame
• The constructors of Frame are
– Frame( )
– Frame(String title)
• The first form creates a standard window that
does not contain a title
• The second form creates a window with the title
specified by title
http://improvejava.blogspot.in/ 4
5. Methods of Frame
• There are several methods you will use when
working with Frame windows
• Setting the Window’s Dimensions
– The setSize( ) method is used to set the dimensions
of the window
• Its signature is shown here
– void setSize(int newWidth, int newHeight)
– void setSize(Dimension newSize)
http://improvejava.blogspot.in/ 5
6. Methods of Frame contd..
• Hiding and Showing a
Window
– After a frame window
has been created, it will
not be visible until you
call
– setVisible( )
– Its signature is shown
here
• void setVisible(boolean
visibleFlag)
• The component is
visible if the argument to
this method is true
http://improvejava.blogspot.in/ 6
7. Methods of Frame contd..
• Setting a Window’s Title
– You can change the title in a frame window
using setTitle( )
– It’s general form
• void setTitle(String newTitle)
• Here, newTitle is the new title for the window
http://improvejava.blogspot.in/ 7
8. Methods of Frame contd..
• Closing a Frame Window
– The window must be removed, when closing
the window
• Window is removed by calling setVisible(false)
– To close the Frame you must implement the
windowClosing( ) method of the
WindowListener interface
– Inside windowClosing( ), you must remove the
window from the screen
http://improvejava.blogspot.in/ 8
9. Summary
• We have learned
– The different constructors of Frame
– The methods of Frame class
http://improvejava.blogspot.in/ 9
10. Quiz
1. Which one is not a method of Frame class ?
a) setVisible()
b) setSize()
c) setDimension()
d) setTitle()
http://improvejava.blogspot.in/ 10
11. Frequently Asked Questions
1. List and explain the different constructors
of Frame class
2. List and explain the different methods of Frame class
http://improvejava.blogspot.in/ 11