Example of Drawing Images
|
This image was loaded with this <APPLET>
tag:
<applet code="DisplayImage" width="158" height="189">
<param name=imagefile value=lightbulb.gif>
<img src=lightbulb.gif width="158" height="189">
</applet>
Here's the code that produced it: |
import java.awt.*;
import java.applet.*;
public class DisplayImage extends Applet {
private Image picture;
public void init() {
String filename = this.getParameter("imagefile");
if (filename != null) {
this.picture = this.getImage(this.getDocumentBase(), filename);
}
}
public void paint(Graphics g) {
if (this.picture != null) {
g.drawImage(this.picture, 0, 0, this);
}
else {
g.drawString("Missing Picture", 20, 20);
}
}
}