これでよろしいですか:
if (additionals[0] != 0){
rightPanel.add(new JLabel(new ImageIcon("IMAGES/ram"+additionals[0]+"gb.gif")));
count++;
}
for(int x = 1; x<=7; x++){
if (additionals[x] != 0){
rightPanel.add(new JLabel(new ImageIcon("IMAGES/image"+x+".gif")));
count++;
}
}
本来はこれでいいのではないですか?
if (additionals[0] != 0){
rightPanel.add(new JLabel(new ImageIcon("IMAGES/ram"+additionals[0]+"gb.gif")));
count++;
}
for(int x = 1; x<=7; x++){
if (additionals[x] != 0){
rightPanel.add(new JLabel(new ImageIcon("IMAGES/image"+ additionals[x]+".gif")));
count++;
}
}
?
コードがより対称的に見えるようになります。それ以外の場合は、問題のある行の前に、ImageIcon を作成するために使用する String を使用して printlns を実行し、それが正しいことを確認します。
例えば:
for(int x = 1; x<=7; x++){
if (additionals[x] != 0){
String imagePath = "IMAGES/image"+x+".gif";
System.out.println("imagePath = " + imagePath);
rightPanel.add(new JLabel(new ImageIcon(imagePath)));
count++;
}
}
そして、出力された文字列をファイル名とパスと比較します。さらに良いのは、新しい File を作成し、それを使用して新しい ImageIcon を作成する前にそのフル パスを出力することです。
注意: コードはテストされていません。