[英]Adding Image In JFrame : Java
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?? 那么hangman1.png应该在哪里,以便正确显示?
Load your "hangman1.png" file as a resource and add it to JLabel
: 加载“ hangman1.png”文件作为资源并将其添加到
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. 在此之前,请将其添加到Java项目中的某个包中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.