Image
Class Diagram
Ancestor class specifications:
java.lang.Object
java.awt.Component
java.awt.Container
javax.swing.JComponent
Image
Class Specification
Invariant
An Image object...
- can display a graphical (.gif, .jpeg, or .tiff type) image within a 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).)
- when it is contained within a proper GUI container the rectangle has dimensions given by width and height. (Note that the image will be stretched as necessary to conform to these dimensions.)
- if necessary, the image is clipped to the boundaries of its GUI container.
Below is a castle Image added to My Window.

Constructor Methods
public Image( int initX, int initY, int w, int h )
post: A new Image object is created
and x == 0 and y == 0
and width == 0 and height == 0
(Note that Images don't appear until an image file has been assigned and the Image object has been added to a visible Container.)
public Image( int initX, int initY, int w, int h )
post: A new Image object is created
and x == initX and y == initY
and width == w and height == h
(Note that Images don't appear until an image file has been assigned and the Image object has been added to a visible Container.)
public Image( int initX, int initY, int w, int h, String f )
pre: f is the name of a valid, accessible image file (such
as those of type .tiff, .gif or .jpeg)
post: A new Image object is created
and x == initX and y == initY
and width == w and height == h
and the image from file f has been assigned to this
(Note that Images don't appear until the Image object has been added to a visible Container.)
Update
Methods
public void setImage( String f )
pre: f is the name of a valid, accessible image file (such
as those of type .tiff, .gif or .jpeg)
post: the image from file f has been assigned to this
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.
Query
Methods
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