Reputation: 1
How do I make an Image
show up in a Java Swing Applet?
Upvotes: 0
Views: 897
Reputation: 108937
Here's an outline of what you need
class myApplet extends JApplet {
private BufferedImage image;
myApplet() {
try {
image = ImageIO.read(new File("insert image path here"));
} catch (IOException ex) {
// handle exception...
}
}
@Override
public void paint(Graphics g) {
g.drawImage(image, 0, 0, null);
}
}
Upvotes: 0
Reputation: 23629
The simplest way is to add it as an Icon to a JLabel that you put on your GUI.
http://download.oracle.com/javase/6/docs/api/javax/swing/JLabel.html#JLabel(javax.swing.Icon)
Upvotes: 1