views:

114

answers:

1

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

A: 

Yes, the image should be in the same folder as the source code. I would recommend to do a folder called images and inside it put all your images and just change "picture.jpg" to "\images\picture.jpg". Check your website directory to see if the image is in the same folder as the source code.

flopex