|
|
[edit] Images
|
| One can display an image using java.awt.Image class. This class is part of AWT framework. Since this class is an abstract superclass of all image classes we cannot instantiate using this class. We need to obtain the instance of Image in a platform specific manner. Different platform handle image rendering in different way. Direct subclasses or implementation classes available on a platform are java.awt.image.BufferedImage and java.awt.image.VolatileImage. Further these classes have there own list of subclasses.
import java.applet.Applet;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.MediaTracker;
import java.net.URL;
public class ImageExample extends Applet {
// image name;
Image imageFileName;
// The MediaTracker class is a utility class to
// track the status of a number of media objects
// like Image in our case.
MediaTracker mediaTracker;
// The applet base URL. Required to load the
// image from this location.
URL baseURL;
public void init() {
mediaTracker = new MediaTracker(this);
// getDocumentbase method gets the applet location.
// This will be helpful only when the image
// file is saved in the same directory location
// from where this applet will be loaded.
try {
baseURL = getDocumentBase();
} catch(Exception e) {
e.printStackTrace();
}
// only .gif and .jpg file are allowed to load.
// save team.jpg in the directory location from
// where you wish to execute this applet.
imageFileName = getImage(baseURL, "team.jpg");
mediaTracker.addImage(imageFileName, 1);
// stop the applet execution by making the mediaTracker to wait
// until the image is fully loaded.
try {
mediaTracker.waitForAll();
}
catch (InterruptedException e) {
}
}
public void paint(Graphics g) {
// draw the image on the screen
g.drawImage(imageFileName, 10, 10, this);
}
}
|
| Audio
|
| Java provides APIs to access and play audio clips. Playing an audio clips in applets is quite simple. Java
|
| Video
|
|
|
|