acm.graphics
Class GImage

java.lang.Object
  |
  +--acm.graphics.GObject
        |
        +--acm.graphics.GImage

public class GImage extends GObject

The GImage class is a graphical object whose appearance is defined by an image.

[examples forthcoming]


Constructor Summary
GImage(double x, double y, java.awt.Image image)
Creates a new GImage object at the specified coordinates.
GImage(double x, double y, java.lang.String name)
Creates a new GImage object at the specified coordinates.
GImage(Image image)
Creates a new GImage object at the origin that displays the specified image.
GImage(String name)
Creates a new GImage object by looking for an image with that name.
 
Method Summary
Image getImage()
Returns the image stored inside this GImage.
void paint(Graphics g)
Implements the paint operation for this graphical object.
void setBounds(double x, double y, double width, double height)
Changes the location and size of the image together.
void setImage(Image image)
Resets the image used by this GImage object to the new image specified as an argument.
void setImage(String name)
Resets the image used by this GImage object to the one identified by the argument name, which is processed exactly as described in the constructors.
 

Inherited Method Summary
void addMouseListener(MouseListener listener)
Adds a mouse listener to this graphical object. [Inherited from GObject]
void addMouseMotionListener(MouseMotionListener listener)
Adds a mouse motion listener to this graphical object. [Inherited from GObject]
boolean contains(double x, double y)
Checks to see whether a point is inside the object. [Inherited from GObject]
Rectangle getBounds()
Returns the bounding box of this object, which is defined to be the smallest rectangle that covers everything drawn by the figure. [Inherited from GObject]
double getHeight()
Returns the height of this object. [Inherited from GObject]
Point getLocation()
Returns the nearest Point corresponding to the location of this object. [Inherited from GObject]
Dimension getSize()
Returns the size of this object as a Dimension. [Inherited from GObject]
double getWidth()
Returns the width of this object. [Inherited from GObject]
double getX()
Returns the x-coordinate of the object. [Inherited from GObject]
double getY()
Returns the y-coordinate of the object. [Inherited from GObject]
boolean isVisible()
Checks to see whether this object is visible. [Inherited from GObject]
void moveToBack()
Moves this object to the back of the display in stacking order. [Inherited from GObject]
void moveToFront()
Moves this object to the front of the display in stacking order. [Inherited from GObject]
void removeMouseListener(MouseListener listener)
Removes a mouse listener from this graphical object. [Inherited from GObject]
void removeMouseMotionListener(MouseMotionListener listener)
Removes a mouse motion listener from this graphical object. [Inherited from GObject]
void scale(double sf)
Scales the object on the screen by the scale factor sf, which applies in both dimensions. [Inherited from GObject]
void scale(double sx, double sy)
Scales the object on the screen by the scale factors sx and sy. [Inherited from GObject]
void setLocation(double x, double y)
Sets the location of this object to the point (x, y). [Inherited from GObject]
void setSize(double width, double height)
Changes the size of this object to the specified width and height. [Inherited from GObject]
void setVisible(boolean visible)
Sets whether this object is visible. [Inherited from GObject]
void translate(double dx, double dy)
Moves the object on the screen using the displacements dx and dy. [Inherited from GObject]

Constructor Detail

public GImage(double x, double y, Image image)

Creates a new GImage object at the specified coordinates. The image parameter is used to initialize the appearance of the image.
 
Usage: GImage gimage = new GImage(x, y, image);
Parameters: 
x  The x-coordinate of the upper left corner of the image
y  The y-coordinate of the upper left corner of the image
image  The image to use as the contents of this GImage
 

public GImage(double x, double y, String name)

Creates a new GImage object at the specified coordinates. The name parameter is used to identify an image to display, as described in the single-argument version of the GImage constructor.
 
Usage: GImage gimage = new GImage(x, y, image);
Parameters: 
x  The x-coordinate of the upper left corner of the image
y  The y-coordinate of the upper left corner of the image
name  The name used to search for the contents of this image
 

public GImage(Image image)

Creates a new GImage object at the origin that displays the specified image.
 
Usage: GImage gimage = new GImage(image);
Parameter: 
image  The image to use as the contents of this GImage
 

public GImage(String name)

Creates a new GImage object by looking for an image with that name. The search for an image by name consists of the following steps:

  1. Check to see if an image with that name has already been defined. If so, return that image.

  2. Check to see if there is a resource available with that name whose contents can be read as an Image. If so, read the image from the resource file.

  3. Load the image from a file with the specified name, relative to the application directory or the applet code base.

 
Usage: GImage gimage = new GImage(name);
Parameter: 
name  The name used to search for the contents of this image
 
Method Detail

public Image getImage()

Returns the image stored inside this GImage.
 
Usage: Image image = gimage.getImage();
Returns: The Image object stored inside this GImage
 

public void paint(Graphics g)

Implements the paint operation for this graphical object. This method is not called directly by clients.

public void setBounds(double x, double y, double width, double height)

Changes the location and size of the image together.
 
Usage: gimage.setBounds(x, y, width, height);
Parameters: 
x  The new x-coordinate for the image
y  The new y-coordinate for the image
width  The new width of the image
height  The new height of the image
 

public void setImage(Image image)

Resets the image used by this GImage object to the new image specified as an argument. Calling setImage automatically changes the size of the image to be equal to that of the image data.
 
Usage: gimage.setImage(image);
Parameter: 
image  The image to use as the contents of this GImage
 

public void setImage(String name)

Resets the image used by this GImage object to the one identified by the argument name, which is processed exactly as described in the constructors. Calling setImage automatically changes the size of the image to be equal to that of the image data.
 
Usage: gimage.setImage(name);
Parameter: 
name  The name used to search for the contents of this image