More Java Graphics
Image Object and Graphic's related methods
Graphics.drawImage(Image im, int x, int
y, ImageObserver obs) |
Draws as much of the specified image as is currently
available at the specified coordinate (x, y) wrt the Applet/Graphics
corridinate system. See example for next method below. Notice in
it that this refers to the current applet |
Image Class |
This is an abstract class which can be used
to store images in it. |
Applet.getImage(URL url, String s) |
Returns an Image object that can then be painted
on the screen. URL is the document path, String is the relative
filename. For example, you might have the following init()
method of some applet class.
import java.awt.*
Image image;
public void init() {
image = getImage(getDocumentBase(), "butch.jpg");
}
public void paint(Graphics g) {
g.drawImage(image, 0, 0, this);
}
|
Image.getGraphics() |
Gets a graphics object to draw into this image.
This will only work for
This is a way for you to write on top of an image if you wish. |
Example:
AudioClip Object and Applet related methods
Applet.play(URL soundDirectory, String
filename); |
Plays the audio clip given the URL and a specifier
that is relative to it.
import java.awt.*
//assumes sound file in the same directory as web-page
public void paint(Graphics g) {
play(getDocumentBase(), "butch.au");
}
|
AudioClip Class |
This is an abstract class which can be used
to store sound data in it. Has the following methods: play(),
loop(), stop() |
Applet.getAudioClip(URL url, String s) |
Returns an AudioClip object that can then be
played. URL is the document path, String is the relative filename.
For example, you might have the following init() method of
some applet class.
import java.awt.*
AudioClip snd;
public void init() {
snd = getAudioClip(getDocumentBase(), "butch.au");
}
public void paint(Graphics g) {
snd.play();
}
|
Example: Looped Sound
|