6
SimpleImage
Download the picture of Stan the Corgi or pick up an image of your choice.
Copy the file in a folder named images.
- Java/SimpleImage
- SimpleImage.java
- images
- stan.jpg
Edit SimpleImage.java:
- // <applet code="SimpleImage" width="400" height="300"></applet>
- import java.applet.Applet;
- import java.awt.*;
- public class SimpleImage extends Applet {
- private Image image;
- private boolean imageLoaded = false;
- public void init() {
- image = getImage(getCodeBase(), "images/stan.jpg");
- prepareImage(image, this);
- }
- public void paint(Graphics g) {
- if (imageLoaded)
- g.drawImage(image, 0, 0, this);
- }
- public boolean imageUpdate(Image image, int infoflags, int x, int y, int width, int height) {
- if ((infoflags & ALLBITS) != 0) {
- imageLoaded = true;
- repaint();
- }
- return (infoflags & (ALLBITS | ABORT)) == 0;
- }
- }
$ javac SimpleImage.java
$ appletviewer SimpleJava.java
Comments