Chapter 1 - Graphical Interface
1. Displaying Images
| /*
This applet will display a gif on screen for now the gif file must be in the same directory as this applet */ import java.awt.*;
public class ImageExample extends Applet
// The applet base URL
// This object will allow you to control
loading
public
void init()
// initialize the MediaTracker
// The try-catch is necassary when the
URL isn't valid
try {
// Here we load the image.
// tell the MediaTracker to kep an eye
on this image, and give it ID 1;
// now tell the mediaTracker to stop the
applet execution
try {
// when the applet gets here then the images is loaded. } public
void paint(Graphics g)
g.drawImage(my_gif,20,20,this); // you can resize the image easily
g.drawImage(my_gif,20,140,30,40,this);
} } // That's all. Images can alos be drawn without
the mediaTracker but then
// Next is the basic GUI (Grphical User Interface)
components.
|