I'm having trouble displaying an image in an applet in eclipse. I'm wondering if there is any alternate way of doing this. I also want to know if there is a reliable online applet tester that displays an applet I made on the web. I'm following the oracle tutorials but they don't work. Here is my code:
Displaying class:
import java.applet.Applet;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.net.URL;
import javax.imageio.ImageIO;
public class usb extends Applet{
static BufferedImage background;
/**
*
*/
private static final long serialVersionUID = 1L;
@Override
public void init() {
// TODO Auto-generated method stub
try {
URL url = new URL(getCodeBase(), "resources/usb_homescreen.png");
background = ImageIO.read(url);
} catch (IOException e) {
}
setSize(1000,500);
add(new goat());
}
}
Canvas class:
import java.awt.Canvas;
import java.awt.Color;
import java.awt.Graphics;
public class goat extends Canvas {
/**
*
*/
private static final long serialVersionUID = 1L;
goat() {
setSize(1000,500);
setBackground(Color.white);
}
@Override
public void paint(Graphics g) {
// TODO Auto-generated method stub
super.paint(g);
g.drawImage(usb.background, 0, 0, null);
}
}
Any ideas about what's wrong?