wheels.users
Class Image

java.lang.Object
  extended bywheels.users.Image
All Implemented Interfaces:
CustomGraphic, Locatable, Sizeable

public class Image
extends Object
implements CustomGraphic, Locatable, Sizeable

A class that can display an image on a DrawingPanel.

Author:
Sanders & van Dam. Object-Oriented Programming in Java.

Constructor Summary
Image(DrawingPanel dp, String file)
          Create an image from the specified filename, in the specified DrawingPanel.
Image(DrawingPanel dp, URL url)
          Create an image from a URL.
Image(String file)
          Create an image from the specified filename, in the wheels.users.Frame's DrawingPanel.
Image(URL url)
          Create an image from the specified URL, in the wheels.users.Frame's DrawingPanel.
 
Method Summary
 boolean contains(Point p)
          See if this Image contains the Point
 void drag(MouseEvent e)
          Override to do something useful.
 Image getAWTImage()
          Get the AWT Image that we are using, not necessary for most users.
 Rectangle getBounds()
          Get the rectangle that indicates the bounds of this Image
 int getHeight()
          Returns the height of this Image.
 Point getLocation()
          Get the location of this Image
 int getRotation()
          Get the rotation for this Image
 Dimension getSize()
          Get the dimensions of this Image
 int getWidth()
          Returns the width of the Image.
 int getXLocation()
          Get the x value of the Image's location.
 int getYLocation()
          Get the y value of the Image's location.
 void hide()
          Hide the Image so it won't paint
 void mouseClicked(MouseEvent e)
          Called when the Panel detects that the mouse was clicked.
 void mouseDragged(MouseEvent e)
          Called when the Panel detects that the mouse was dragged.
 void mousePressed(MouseEvent e)
          Called when the Panel detects that the mouse was pressed.
 void mouseReleased(MouseEvent e)
          Called when the Panel detects that the mouse was released.
 void paint(Graphics2D g)
          Normal users need not use this!
 void setLocation(int x, int y)
          Set the location of the Image.
 void setLocation(Point p)
          Set the location of this Image
 void setRotation(int degrees)
          Set the rotation for this Image
 void setSize(Dimension d)
          Set the dimensions of this Image
 void setSize(int width, int height)
          Set the dimensions of this Image
protected  void setup(DrawingPanel dp)
          Normal users need not use this!
 void show()
          Show the Image so it paints
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Image

public Image(String file)
Create an image from the specified filename, in the wheels.users.Frame's DrawingPanel. Note that if you are running on Windows, the location of the image must be in your classpath.

Parameters:
file - the filename to take this image form (gif or jpg).

Image

public Image(URL url)
Create an image from the specified URL, in the wheels.users.Frame's DrawingPanel.

Parameters:
url - the URL to take this image form (gif or jpg)

Image

public Image(DrawingPanel dp,
             String file)
Create an image from the specified filename, in the specified DrawingPanel. Note that if you are running on Windows, the location of the image must be in your classpath.

Parameters:
dp - the DrawingPanel for this image
file - the filename to take this image form (gif or jpg).

Image

public Image(DrawingPanel dp,
             URL url)
Create an image from a URL.

Parameters:
dp - the DrawingPanel for this image
url - the URL to take this image form (gif or jpg)
Method Detail

setup

protected void setup(DrawingPanel dp)
Normal users need not use this!

Use the media tracker to load the image, then initialize everything else.


setSize

public void setSize(Dimension d)
Set the dimensions of this Image

Specified by:
setSize in interface Sizeable
Parameters:
d - the new Dimension for this Image

setSize

public void setSize(int width,
                    int height)
Set the dimensions of this Image

Specified by:
setSize in interface Sizeable

getSize

public Dimension getSize()
Get the dimensions of this Image

Specified by:
getSize in interface Sizeable
Returns:
the Dimension for this Image

getWidth

public int getWidth()
Returns the width of the Image.

Specified by:
getWidth in interface Sizeable

getHeight

public int getHeight()
Returns the height of this Image.

Specified by:
getHeight in interface Sizeable

setLocation

public void setLocation(Point p)
Set the location of this Image

Specified by:
setLocation in interface Locatable
Parameters:
p - the new Point for this Image

setLocation

public void setLocation(int x,
                        int y)
Set the location of the Image.

Specified by:
setLocation in interface Locatable

getLocation

public Point getLocation()
Get the location of this Image

Specified by:
getLocation in interface Locatable
Returns:
the Point for this Image

getXLocation

public int getXLocation()
Get the x value of the Image's location.

Specified by:
getXLocation in interface Locatable

getYLocation

public int getYLocation()
Get the y value of the Image's location.

Specified by:
getYLocation in interface Locatable

hide

public void hide()
Hide the Image so it won't paint


show

public void show()
Show the Image so it paints


getAWTImage

public Image getAWTImage()
Get the AWT Image that we are using, not necessary for most users.

Returns:
the real AWT image

contains

public boolean contains(Point p)
See if this Image contains the Point

Specified by:
contains in interface CustomGraphic
Parameters:
p - the Point to test

setRotation

public void setRotation(int degrees)
Set the rotation for this Image

Parameters:
degrees - the degrees (clockwise) that this should rotate

getRotation

public int getRotation()
Get the rotation for this Image

Returns:
the degrees (clockwise) that this should rotate

paint

public void paint(Graphics2D g)
Normal users need not use this!

Rotate the Graphics Context if necessary, the paint, then reset the rotation

Specified by:
paint in interface CustomGraphic
Parameters:
g - the Graphics2D you should use to paint your graphic

getBounds

public Rectangle getBounds()
Get the rectangle that indicates the bounds of this Image

Returns:
the java.awt.Rectangle that indicates our bounds.

drag

public void drag(MouseEvent e)
Override to do something useful.


mouseClicked

public void mouseClicked(MouseEvent e)
Called when the Panel detects that the mouse was clicked. If the click is within this Image. Override to do somthing useful.

Specified by:
mouseClicked in interface CustomGraphic

mouseDragged

public void mouseDragged(MouseEvent e)
Called when the Panel detects that the mouse was dragged. Override to do something useful.

Specified by:
mouseDragged in interface CustomGraphic

mousePressed

public void mousePressed(MouseEvent e)
Called when the Panel detects that the mouse was pressed. Override to do something useful.

Specified by:
mousePressed in interface CustomGraphic

mouseReleased

public void mouseReleased(MouseEvent e)
Called when the Panel detects that the mouse was released. Override to do something useful.

Specified by:
mouseReleased in interface CustomGraphic