【发布时间】:2014-07-27 04:54:36
【问题描述】:
今天早上我正在测试我的程序并运行它,它运行良好。一个小时后,我的按钮不再出现我的图像了,我不知道为什么。
JButton chuck = new JButton(new ImageIcon("chucknorris.jpg"));//this part of program runs this if user picks lizard
chuck.setSize(210,175); //sets size of button
chuck.setLocation(25,75); //sets location of button
chuck.addActionListener(new ActionListener() {
public void actionPerformed (ActionEvent e) {
int answer = JOptionPane.showConfirmDialog(null, "\t\t STATS\nAttack: 10\nDefence: 15\nspecial: bomb");
if (answer == JOptionPane.NO_OPTION) {
System.out.println("No button clicked");
} else if (answer == JOptionPane.YES_OPTION) {
x = 1;
b = 0;
} else if (answer == JOptionPane.CLOSED_OPTION) {
System.out.println("JOptionPane closed");
}
}
});
【问题讨论】:
-
是时候做一些调试了。
-
您的图像存储在哪里?我也劝你不要使用
null布局 -
我的图像与我的 java 文件一起存储在一个文件夹中
-
尝试将图片放在存放.class文件的文件夹中
标签: java image swing embedded-resource imageicon