This week's book giveaway is in the General Computing forum. We're giving away four copies of Arduino in Action and have Martin Evans, Joshua Noble, and Jordan Hochenbaum on-line! See this thread for details.
I have downloaded the folowing code from javaranch site. Able to compile the java prog, im getting msgapplet started at the status bar but image is not getting loaded,I tried printing the msg in the where im calling g.drawImage () method.String is displayed on the applet but image is not coming.can any one tel what could be the reason .
thnx & regards madhavi
import java.applet.* ; import java.awt.* ;
public class LoadAGifMsg extends Applet { private Image theHorse ; private Image theMoose ; private boolean showWaitMsg = true ; // will be set to false after image downloads
public void init() { // anything in here will run BEFORE the paint() method is called, // even if you call repaint() now inside init } // close init
public void loadGraphics() { // now load the graphics - this is like your "real" init theHorse = getImage( getCodeBase() , "M1.JPEG" ); theMoose = getImage( getCodeBase() , "M2.JPEG" ); MediaTracker mt = new MediaTracker( this ); mt.addImage( theHorse , 0 ); mt.addImage( theMoose , 1 );
try { mt.waitForAll(); // block here until images are downloaded } catch ( InterruptedException e ) { }
showWaitMsg = false ; // it is safe for paint to draw the image now repaint(); } // close loadGraphics
public void paint( Graphics g ) { // test a boolean to if the "loading" message should be displayed if ( showWaitMsg ) { g.drawString( "Please wait... loading..." , 20 , 20 ); loadGraphics(); // call the method that actually loads the graphics } else { g.drawImage( theHorse , 25 , 25 , this ); g.drawImage( theMoose , 25 , 130 , this ); } } // close paint }