acm.graphics
Class GImage

java.lang.Object
  |
  +--acm.graphics.GObject
        |
        +--acm.graphics.GImage
All Implemented Interfaces:
Cloneable, GResizable, GScalable

public class GImage
extends GObject
implements GResizable, GScalable

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


Constructor Summary
GImage(Image image)
          Creates a new GImage object at the origin that displays the specified image.
GImage(Image image, double x, double y)
          Creates a new GImage object at the specified coordinates.
GImage(String name)
          Creates a new GImage object by looking for an image with that name.
GImage(String name, double x, double y)
          Creates a new GImage object at the specified coordinates.
 
Method Summary
protected  Rectangle getAWTBounds()
          Returns an AWT Rectangle that specifies the bounds of this object.
 GRectangle getBounds()
          Returns the bounding box of this object.
 Image getImage()
          Returns the image stored inside this GImage.
 GDimension getSize()
          Returns the size of this object as a GDimension.
 void paint(Graphics g)
          Implements the paint operation for this graphical object.
 void scale(double sf)
          Scales the object on the screen by the scale factor sf, which applies in both dimensions.
 void scale(double sx, double sy)
          Scales the object on the screen by the scale factors sx and sy.
 void setBounds(double x, double y, double width, double height)
          Changes the bounds of this object to the specified values.
 void setBounds(GRectangle bounds)
          Changes the bounds of this object to the values from the specified GRectangle.
 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.
 void setSize(double width, double height)
          Changes the size of this object to the specified width and height.
 void setSize(GDimension size)
          Changes the size of this object to the specified GDimension.
 
Methods inherited from class acm.graphics.GObject
addActionListener, addMouseListener, addMouseMotionListener, areMouseListenersEnabled, colorName, contains, contains, fireActionEvent, fireActionEvent, fireMouseListeners, getColor, getComponent, getHeight, getLocation, getObjectColor, getParent, getWidth, getX, getY, isVisible, move, movePolar, paintObject, paramString, pause, removeActionListener, removeMouseListener, removeMouseMotionListener, repaint, sendBackward, sendForward, sendToBack, sendToFront, setColor, setLocation, setLocation, setParent, setVisible, start, start, toString, updateEnabledList
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

GImage

public GImage(Image image)
Creates a new GImage object at the origin that displays the specified image.
Parameters:
image - The image to use as the contents of this GImage

GImage

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

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.

Parameters:
name - The name used to search for the contents of this image

GImage

public GImage(String name,
              double x,
              double y)
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.
Parameters:
name - The name used to search for the contents of this image
x - The x-coordinate of the upper left corner of the image
y - The y-coordinate of the upper left corner of the image
Method Detail

getAWTBounds

protected Rectangle getAWTBounds()
Returns an AWT Rectangle that specifies the bounds of this object.
Returns:
A Rectangle that specifies the bounds of this object

getBounds

public GRectangle getBounds()
Returns the bounding box of this object.
Overrides:
getBounds in class GObject
Returns:
The bounding box for this object

getImage

public Image getImage()
Returns the image stored inside this GImage.
Returns:
The Image object stored inside this GImage

getSize

public GDimension getSize()
Returns the size of this object as a GDimension.
Overrides:
getSize in class GObject
Returns:
The size of this object

paint

public void paint(Graphics g)
Implements the paint operation for this graphical object. This method is not called directly by clients.
Overrides:
paint in class GObject
Following copied from class: acm.graphics.GObject
Parameters:
g - The graphics context into which the painting is done

scale

public final void scale(double sf)
Scales the object on the screen by the scale factor sf, which applies in both dimensions.
Specified by:
scale in interface GScalable
Parameters:
sf - The factor used to scale all coordinates in both dimensions

scale

public void scale(double sx,
                  double sy)
Scales the object on the screen by the scale factors sx and sy.
Specified by:
scale in interface GScalable
Parameters:
sx - The factor used to scale all coordinates in the x direction
sy - The factor used to scale all coordinates in the y direction

setBounds

public void setBounds(double x,
                      double y,
                      double width,
                      double height)
Changes the bounds of this object to the specified values.
Specified by:
setBounds in interface GResizable
Parameters:
x - The new x-coordinate for the object
y - The new y-coordinate for the object
width - The new width of the object
height - The new height of the object

setBounds

public final void setBounds(GRectangle bounds)
Changes the bounds of this object to the values from the specified GRectangle.
Specified by:
setBounds in interface GResizable
Parameters:
bounds - A GRectangle specifying the new bounds

setImage

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.
Parameters:
image - The image to use as the contents of this GImage

setImage

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.
Parameters:
name - The name used to search for the contents of this image

setSize

public void setSize(double width,
                    double height)
Changes the size of this object to the specified width and height.
Specified by:
setSize in interface GResizable
Parameters:
width - The new width of the object
height - The new height of the object

setSize

public final void setSize(GDimension size)
Changes the size of this object to the specified GDimension.
Specified by:
setSize in interface GResizable
Parameters:
size - A GDimension object specifying the size