你获取的方式 对吗?? 比如你在你的 Test类中 用,那么可以这样 ImageIcon test = new ImageIcon(Test.class.getResourceAsStream("/com/test/test.gif"));
不過 我感覺 不是所有的gif格式 都可以顯示
public class LayMines { ImageIcon mineIcon; public LayMines() { // TODO Auto-generated constructor stub mineIcon=new ImageIcon("WINMINE1.gif"); } public void layMinesForBlock(Block block[][],int minecount){ int row=block.length; //通过一位数组获取行 int coclum=block[0].length; //通过二维获取列 LinkedList<Block> list =new LinkedList<Block>(); //用栈结构来存储数据 for (int i = 0; i < row; i++) { for (int j = 0; j <coclum; j++) { list.add(block[i][j]);
}
} while (minecount>0) { int size=list.size(); int random=(int)(Math.random()*size); Block block1=list.get(random); block1.setisMine(true); block1.setName("雷"); block1.setimageIcon(mineIcon); list.remove(random); minecount--;
比如你在你的 Test类中 用,那么可以这样
ImageIcon test = new ImageIcon(Test.class.getResourceAsStream("/com/test/test.gif"));
ImageIcon mineIcon;
public LayMines() {
// TODO Auto-generated constructor stub
mineIcon=new ImageIcon("WINMINE1.gif");
}
public void layMinesForBlock(Block block[][],int minecount){
int row=block.length;
//通过一位数组获取行
int coclum=block[0].length;
//通过二维获取列
LinkedList<Block> list =new LinkedList<Block>();
//用栈结构来存储数据
for (int i = 0; i < row; i++) {
for (int j = 0; j <coclum; j++) {
list.add(block[i][j]);
}
}
while (minecount>0) {
int size=list.size();
int random=(int)(Math.random()*size);
Block block1=list.get(random);
block1.setisMine(true);
block1.setName("雷");
block1.setimageIcon(mineIcon);
list.remove(random);
minecount--;
}
是静态图标啊,我就像这样写的。怎么无法显示?