notes projects homework the dump links
 

Images (if you want an image in a class)

 

You need to initialize the image and then draw it. To initialize a file in the same directory as your class:

 

Create a global for the image:

Image img;

 

In your init statement or anywhere really

img=getToolkit().getImage(getClass().getResource("liftoff.jpg"));

if you want the image file in another directory, you would say images/theFileName.jpg if it was in the images directory

 

and then draw it in paint (or using buffergraphics anywhere_:

 

g.drawImage(img,0,0,this);

 

 

 

Scaling images on the fly
Use

drawImage(img, x,y, width, height,this);

or more specificly

drawImage(img, dx1, dy1, dx2, dy2, sx1, sy1, sx2, sy2,this);

where:

dx1 - the x coordinate of the first corner of the destination rectangle.
dy1 - the y coordinate of the first corner of the destination rectangle.
dx2 - the x coordinate of the second corner of the destination rectangle.
dy2 - the y coordinate of the second corner of the destination rectangle.
sx1 - the x coordinate of the first corner of the source rectangle.
sy1 - the y coordinate of the first corner of the source rectangle.
sx2 - the x coordinate of the second corner of the source rectangle.
sy2 - the y coordinate of the second corner of the source rectangle.