Component Class Diagram

 

 

 

 

 

 

Ancestor class specifications:

java.lang.Object


Component Class Specification

            Invariant

                        A java.awt.Component object...

-       is a transparent rectangular region

-       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).)

 

Below is a Component added to the content pane of a JFrame.  The Component is depicted as a dashed rectangle, although it would be transparent on an actual computer display.

Constructor Methods

public Component( )

post: A new Component object is created

         and  backColor and foreColor are transparent

         (Note that Components also donÕt appear until added.)

 

            Update Methods

public void paint( java.awt.Graphics g )

post:  An invisible image has been drawn using g as its graphics context.

note:  This method should be overridden in order to draw a desired image.

 

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 setLocation( int initX,  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 Container, and its content, as soon as possible.

       

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

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

       

public void addMouseListener (java.awt.event.MouseListener lis )

post:  Mouse listener events (mouseClicked, mouseEntered, mouseExited, mousePressed, and mouseReleased) have been redirected to the lis object

       

public void addMouseMotionListener( java.awt.event.MouseMotionListener lis )

post:  Mouse motion listener events (mouseDragged and mouseMoved) 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

 

public java.awt.Container getParent( )

post: this Component is added to another

                  implies result == the Container to which this is added

         and  this Component is not added to another implies result == null