How do I make an Image show up in a Java Swing Applet
How do I make an Image
sho开发者_运维问答w up in a Java Swing Applet?
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)
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);
}
}
精彩评论