JFrame Class Diagram

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Ancestor class specifications:

java.lang.Object
java.awt.Component
java.awt.Container
java.awt.Window
java.awt.Frame

 

JFrame Class Specification

            Invariant

                        A JFrame object...

-       is a rectangular window.

-       is placed on a computer screen with its upper-left corner x pixels from the left and y pixels from the top. (The upper left corner of the screen is (0, 0).)

-       has usable dimension of width pixels from side to side and height pixels from top to bottom; this region has a background color of backColor.

-       has title displayed in the window's title bar

Below is a JFrame with a gray backColor on a white screen.

Constructor Methods

public JFrame( String s )

post: A new JFrame (window) object is created

         and  title == s

         (Note that this method needs to be followed by calls to setBounds and setVisible in order to make the object appear.)

 

            Update Methods

public void add( java.awt.Component c, int j )

pre:   j == 0 for best results

post:  The pic graphical object will be drawn upon the content pane of this JFrame

 

public void remove( java.awt.Component c )

post:  The pic graphical object will be removed from this JFrame

note:  Nothing occurs if pic was not added to this JFrame at the time of the call.

 

public void repaint( )

post:  Causes the Java virtual machine to update the display of this object as soon as possible.

 

public void setBackground( java.awt.Color c )

post:  backColor == c

 

public void setForeground (java.awt.Color c )

post:  foreColor == c

 

public void setBounds( int initX,  int initY,  int w,  int h)

post: x == initX   and   y == initY

         and   width == w    and   height == h

 

public void setLayout( java.awt.LayoutManager m ) )

pre:   m == null   (for use in this book)

post:  Objects added to the frame will be arranged via m

note: In this book an argument of null is suggested.

 

public void setVisible( boolean b )

post:  b == true implies this JFrame is made visible and brought to the foreground (in front of other windows).

       

public void addKeyListener( java.awt.event.KeyListener lis )

post:  Key listener events (keyPressed, keyReleased and keyTyped) have been redirected to the lis object

 

            Query Methods

public java.awt.Color  getBackground( )

post:  result == backColor

 

public java.awt.Color  getForeground( )

post:  result == foreColor

 

public int getX( )

post: result == x

 

public int getY( )

post: result == y

 

public int getWidth( )

post: result == width

 

public int getHeight( )

post: result == height