CS 596 Java Programming Fall Semester, 1998 Image Applet |
||
---|---|---|
San Diego State University -- This page last updated 16-Dec-98 |
<APPLET ARCHIVE="AppletClasses.jar" CODE="ImageApplet.class" WIDTH=350 HEIGHT=100> Your browser does not support Java applets, so you can not see this applet operate. </APPLET>
import java.awt.*; import java.applet.Applet; import java.awt.Image; public class ImageApplet extends Applet { private Image ioStream; private String errorMessage = null; public void init() { try { ioStream = getImage( getCodeBase(), "IO1002.gif" ); //Insure image is downloaded before showing it MediaTracker tracker = new MediaTracker( this ); tracker.addImage( ioStream, 0 ); tracker.waitForID( 0 ); repaint(); } catch (InterruptedException netProblem ) { errorMessage = "Could not reach image"; } } public void paint( Graphics display) { if ( errorMessage == null ) display.drawImage( ioStream, 0, 0, this ); else display.drawString( errorMessage, 10, 10 ); } }