Adding Image In JFrame : Java

71 Views Asked by At

If I Use This Way To Add image in panel

static ImageIcon bg = new ImageIcon("hangman1.png");

Then Where Should Be Mine hangman1.png should be so it display correctly??

1

There are 1 best solutions below

0
On

Load your "hangman1.png" file as a resource and add it to JLabel:

JLabel label = new JLabel(new ImageIcon(getClass().getResource("/path/to/your/image/hangman1.png")));

Before of that, add it into some package in your Java project.