我在将鼠标的图像图标加载到程序中的Jbutton时遇到麻烦。
我希望图像在打开Jar文件时能够正常工作,因此使用该程序的任何计算机也将能够看到该图像。
注意:我正在使用Netbeans,并将图像放置在我的SRC路径中,如下所示:
当前,这是我的图像加载代码:
ImageIcon img = new ImageIcon(getClass().getResource("mouse.png"));
JButton button1 = new JButton();
button1.setIcon(img);
button1.setPreferredSize(new Dimension(100, 100));
button1.setBounds(x, y, 100, 100);
add(button1);
我应该改为通过URL链接加载图像吗?