我有一个程序运行并没有在eclipse中抛出运行时错误,它应该在程序结束时将一个图像设置为JButton作为结果,但图像永远不会放到按钮上。该程序在DrJava中运行良好,但为了创建jar文件,我将其转移到了eclipse。如何将图像添加到eclipse中的项目目录中?
我在另一个问题中看到,有人有一个类似的问题,说图像应该放在项目目录中,而不是src目录,但它没有解释如何真正解决问题... im新的eclipse所以如果有人可以帮助我ID感谢它。
这里是如何将图像设置在我的代码:
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"));
}
}
}
显示代码和项目布局。 – 2012-07-09 14:09:53
它不是你想要的主类还是添加图像的类 – user1469139 2012-07-09 14:10:35
@JBNizet我添加了一段添加图像的代码 – user1469139 2012-07-09 14:18:22