Trouble adding Image to a JPanel
- by user1276078
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 );
}
}