Rectangle Class Diagram

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Ancestor class specifications:

java.lang.Object
java.awt.Component
java.awt.Container
javax.swing.JComponent


Rectangle Class Specification

            Invariant

                        A Rectangle object...

-       is drawn as a rectangular solid.

-       should be added to a container object with its upper-left corner x pixels from the left and y pixels from the top. (The upper left corner of the container is (0, 0).)

-       when it is contained within a proper GUI container the rectangle appears  in color color and the dimensions of the rectangle are given by width and height.

-       if necessary, the rectangle image is clipped to the boundaries of its GUI container.

 

Below is a black Rectangle added to My Window.

Constructor Methods

public Rectangle( int initX,  int initY,  int w,  int h )

post: A new Rectangle object is created

         and   color == Color.black

         and   x  == initX   and   y == initY

         and   width == w   and   height == h

         (Note that Rectangles don't appear until added.)

 

            Update Methods

public void setBackground( java.awt.Color c )

post:  color == c

 

public void setLocation( int intX,  int initY )

post: x == initX   and   y == initY

 

public void setSize( int w,  int h )

post: width == w   and   height == h

 

public void repaint( )

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

 

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

pre:   j == 0 for best results

post:  The pic graphical object will be drawn upon this Rectangle

 

 

            Query Methods

public java.awt.Color  getBackground( )

post:  color == c

 

public int getX( )

post: result == x

 

public int getY( )

post: result == y 

 

public int getWidth( )

post: result == width 

 

public int getHeight( )

post: result == height 

 

public java.awt.Container getParent( )

post: this Rectangle is added to a Container

                  implies result == the Container to which this is added

         and  this Rectangle is not added implies result == null