【发布时间】:2012-07-09 14:06:52
【问题描述】:
我有一个程序可以运行并且不会在 Eclipse 中引发运行时错误,它应该在程序结束时将图像设置为 JButton,但图像永远不会放在按钮上。该程序在 DrJava 中运行良好,但我转移到 eclipse 以制作 jar 文件。
我在另一个发布的问题中看到有人遇到类似的问题,说应该将图像放入项目目录而不是 src 目录,但它没有解释如何实际解决问题......我是 eclipse 的新手,所以如果有人可以帮助我感谢它。
这是在我的代码中设置图像的方式:
public void tempSelection70 (int fRate, int wbTemp, int rcTons, int a, int r)
{
for (int model = 0; model < 7; model++)
{
MyArray y = new MyArray(tons70FCharts[model], "t");
int[][] x = y.getArray();
int t = x[a][r];
if (rcTons == t)
{
tableButton = new JButton(new ImageIcon(tablesFor70[model], tablesFor70[model]));
break;
}
else
{
tableButton = new JButton(new ImageIcon("CANNOT_FIND_MODEL.GIF", "SCROLL"));
}
}
for (int model = 0; model < 7; model++)
{
MyArray y = new MyArray(flow70FCharts[model], "f");
int[][] x = y.getArray();
int t = x[a][r];
if (fRate == t)
{
tableButton = new JButton(new ImageIcon(tablesFor70[model], tablesFor70[model]));
break;
}
else
{
tableButton = new JButton(new ImageIcon("CANNOT_FIND_MODEL.GIF", "SCROLL"));
}
}
}
【问题讨论】:
-
显示代码和项目的布局。
-
你想要主类还是添加图像的类
-
@JBNizet 我添加了一段添加图片的代码
标签: java eclipse image jar directory