public class GImage extends GObject implements GResizable, GScalable
GImage
class is a graphical object whose appearance is
defined by an image.Constructor and Description |
---|
GImage(java.awt.Image image)
Creates a new
GImage object at the origin that displays
the specified image. |
GImage(java.awt.Image image,
double x,
double y)
Creates a new
GImage object at the specified coordinates. |
GImage(java.lang.String name)
Creates a new
GImage object by looking for an image with that
name. |
GImage(java.lang.String name,
double x,
double y)
Creates a new
GImage object at the specified coordinates. |
Modifier and Type | Method and Description |
---|---|
GRectangle |
getBounds()
Returns the bounding box of this object.
|
java.awt.Image |
getImage()
Returns the image stored inside this
GImage . |
GDimension |
getSize()
Returns the size of this object as a
GDimension . |
void |
paint(java.awt.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(java.awt.Image image)
Resets the image used by this
GImage object to the new image
specified as an argument. |
void |
setImage(java.lang.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 . |
addActionListener, addMouseListener, addMouseMotionListener, contains, contains, fireActionEvent, fireActionEvent, getColor, getHeight, getLocation, getParent, getWidth, getX, getY, isVisible, move, movePolar, pause, removeActionListener, removeMouseListener, removeMouseMotionListener, sendBackward, sendForward, sendToBack, sendToFront, setColor, setLocation, setLocation, setParent, setVisible, toString
public GImage(java.awt.Image image)
GImage
object at the origin that displays
the specified image.image
- The image to use as the contents of this GImage
public GImage(java.lang.String name)
GImage
object by looking for an image with that
name. The search for an image by name consists of the following steps:
Image
. If so, read the image
from the resource file.
name
- The name used to search for the contents of this imagepublic GImage(java.awt.Image image, double x, double y)
GImage
object at the specified coordinates. The
image
parameter is used to initialize the appearance of the image.image
- The image to use as the contents of this GImage
x
- The x-coordinate of the upper left corner of the imagey
- The y-coordinate of the upper left corner of the imagepublic GImage(java.lang.String name, double x, double y)
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.name
- The name used to search for the contents of this imagex
- The x-coordinate of the upper left corner of the imagey
- The y-coordinate of the upper left corner of the imagepublic void setImage(java.awt.Image image)
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.image
- The image to use as the contents of this GImage
public void setImage(java.lang.String name)
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.name
- The name used to search for the contents of this imagepublic java.awt.Image getImage()
GImage
.Image
object stored inside this GImage
public void paint(java.awt.Graphics g)
paint
operation for this graphical object. This method
is not called directly by clients.public void setSize(double width, double height)
setSize
in interface GResizable
width
- The new width of the objectheight
- The new height of the objectpublic final void setSize(GDimension size)
GDimension
.setSize
in interface GResizable
size
- A GDimension
object specifying the sizepublic GDimension getSize()
GDimension
.public void setBounds(double x, double y, double width, double height)
setBounds
in interface GResizable
x
- The new x-coordinate for the objecty
- The new y-coordinate for the objectwidth
- The new width of the objectheight
- The new height of the objectpublic final void setBounds(GRectangle bounds)
GRectangle
.setBounds
in interface GResizable
bounds
- A GRectangle
specifying the new boundspublic GRectangle getBounds()
public void scale(double sx, double sy)
sx
and sy
.