我有一個程序運行並沒有在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