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.

  1. Java/SimpleImage
    1. SimpleImage.java
    2. images
      1. stan.jpg

Edit SimpleImage.java:

  1. // <applet code="SimpleImage" width="400" height="300"></applet>
  2.  
  3. import java.applet.Applet;
  4. import java.awt.*;
  5.  
  6. public class SimpleImage extends Applet {
  7.     private Image image;
  8.  
  9.     private boolean imageLoaded = false;
  10.  
  11.     public void init() {
  12.         image = getImage(getCodeBase(), "images/stan.jpg");
  13.         prepareImage(image, this);
  14.     }
  15.  
  16.     public void paint(Graphics g) {
  17.         if (imageLoaded)
  18.             g.drawImage(image, 0, 0, this);
  19.     }
  20.  
  21.     public boolean imageUpdate(Image image, int infoflags, int x, int y, int width, int height) {
  22.         if ((infoflags & ALLBITS) != 0) {
  23.             imageLoaded = true;
  24.             repaint();
  25.         }
  26.         return (infoflags & (ALLBITS | ABORT)) == 0;
  27.     }
  28. }
$ javac SimpleImage.java
$ appletviewer SimpleJava.java

Comments

Your comment:
[p] [b] [i] [u] [s] [quote] [pre] [br] [code] [url] [email] strip help 2000

Enter a maximum of 2000 characters.
Improve the presentation of your text with the following formatting tags:
[p]paragraph[/p], [b]bold[/b], [i]italics[/i], [u]underline[/u], [s]strike[/s], [quote]citation[/quote], [pre]as is[/pre], [br]line break,
[url]http://www.izend.org[/url], [url=http://www.izend.org]site[/url], [email]izend@izend.org[/email], [email=izend@izend.org]izend[/email],
[code]command[/code], [code=language]source code in c, java, php, html, javascript, xml, css, sql, bash, dos, make, etc.[/code].