How to load an image to an applet?

2nd Image won't load in Java Applet?

  • I have 2 images and I am using g.drawImage() to draw them, but only 1 of the 2 images load. Here are the main parts of my code: private Image loginImages[] = new Image[2]; // Array of images MediaTracker tracker = new MediaTracker(this); // MediaTracker to track images. do I need this? in init() method: loginImages[0] = getImage(getDocumentBase(), "test1.gif"); tracker.addImage(loginImages[0], 0); loginImages[1] = getImage(getDocumentBase(), "test2.gif"); tracker.addImage(loginImages[1], 1); in paint method: g.drawImage(loginImages[0] ,0 ,0, this); g.drawImage(loginImages[1], 30, 30, this); Like I said, loginImages[0] loads fine, but loginImages[1] does not show up, even if I comment the first image out. Both of the images are in the same directory, and they are valid .gif files. Am I missing something or doing something wrong? Any suggestions? Thanks.

  • Answer:

    Ugh, who uses applets? Note that nowadays everyone uses javascript, ajax, and CSS to give a rich client presentation. We don't use applets anymore. Sorry I can't help with the homework assignment or whatever. I am a professional java developer, but we don't use applets. Nobody does except in very specialized situations.

cheeser1... at Yahoo! Answers Visit the source

Was this solution helpful to you?

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.