Images in Applet not showing in web page

Posted by Leanne C on Stack Overflow See other posts from Stack Overflow or by Leanne C
Published on 2010-04-13T16:37:59Z Indexed on 2010/04/14 4:23 UTC
Read the original article Hit count: 314

Filed under:
|
|
|

I am trying to display a JPEG image and a moving dot on a Java applet which I am using on a web based application. However, when I run the applet it works fine, but when I display the applet from the JSP page, I get the moving dot but not the JPEG image.

Is there a specific folder where the JPEG needs to be?

These are the 2 methods i use for drawing the picture and the moving dot on the screen.

public class mapplet extends Applet implements Runnable {

int x_pos = 10;
int y_pos = 100;
int radius = 20;
Image img, img2;
Graphics gr;
URL base;
MediaTracker m;

@Override
public void init() {

        mt = new MediaTracker(this);

        try {
            //getDocumentbase gets the applet path.
           base = getCodeBase();
          img = getImage(base, "picture.jpg");
            m.addImage(img, 1);
            m.waitForAll();
        } catch (InterruptedException ex) {
            Logger.getLogger(movement.class.getName()).log(Level.SEVERE, null, ex);
       }

public void paint (Graphics g) {

 g.drawImage(img, 0, 0, this);
// set color
 g.setColor (Color.red);

// paint a filled colored circle
g.fillOval (x_pos - radius, y_pos - radius, 2 * radius, 2 * radius);

}

The code one below is the call from the jsp page

<applet archive="mapplet.jar" code="myapplets/mapplet.class" width=350 height=200>
</applet>

The jar file and the picture are in the same folder as the jsp page, and there is also a folder containing the contents of the class and image of the applet in the web section of the application. The applet loads fine however the picture doesn't display. I think it's not the code but the location of the picture that is causing a problem.

Thanks

© Stack Overflow or respective owner

Related posts about java

Related posts about applet