Trouble adding Image to a JPanel
Posted
by
user1276078
on Stack Overflow
See other posts from Stack Overflow
or by user1276078
Published on 2012-06-29T21:07:03Z
Indexed on
2012/06/29
21:16 UTC
Read the original article
Hit count: 269
I'm making a video game, and I need to add an image to a JPanel and then add that JPanel to a JFrame. All of the tutorials I've seen say to add it to a JLabel, but the image needs to be able to move around. Unless you can move a JLabel around, I can't do that. How would I be able to add an Image directly to a JPanel. This is what I have so far, but it is just like it was on a JApplet
class Penguin extends JPanel {
public Image image;
public void paintComponent( Graphics g ) {
image = getImage( getDocumentBase(), "Penguins.jpg" );
g.drawImage( image, 0, 0, this );
}
}
© Stack Overflow or respective owner