Container
Class Diagram

Ancestor class specifications:
Container
Class Specification
Invariant
A java.awt.Container object...
- is a transparent rectangular region
- may 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 Container added to the content pane of a JFrame. The Container is depicted as a dashed rectangle, although it would be transparent on an actual computer display.

Constructor Methods
public Container( )
post: A new Component object is created
and backColor and foreColor are transparent
(Note that Containers also donÕt appear until added.)
Update
Methods
public void add( java.awt.Component c, int j )
pre: j == 0
post: c is placed on top of this Container located c.getX() pixels from the left and c.getY() pixels from the top of this Container.
public void remove( java.awt.Component c )
post: The c graphical object will be removed from this Container
note: Nothing occurs if c was not added to this Container.
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 setLayout( java.awt.LayoutManager m ) )
post: m is established as the layout manager
for this Container.
note: In this book an argument of null is suggested.
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 Container is added to another
implies result ==
the Container to
which this is added
and this Container is not added to another implies result == null