}
/**
* 把某个图片以组件的方式加入窗体
* @param imgPath 图片路径
* @param x x
* @param y y
* @param width 宽度
* @param height 高度
* @return 添加完的组件
*/
void addComponent(int tag, String imgPath, int x, int y) {
ImageIcon img = new ImageIcon(imgPath);
//创建 JLabel 并把 ImageIcon
通过构造方法传参传入
//把食物放到盘子里
JLabel componet = new JLabel(img);
//设置盘子在桌布上的位置和大小
componet.setBounds(x, y, imgSize, imgSize);
//把盘子放到桌布上
zhuobu.add(componet);
switch (tag) {
case 1:
box = componet;
break;
case 2:
goal = componet;
break;
case 3:
worker = componet;
break;
}
}
void addWall(String imgPath, int[][] loactions) {
ImageIcon wallImg = new ImageIcon(imgPath);
walls = new JLabel[66 + loactions.length];
for (int i = 0; i < walls.length; i++) {
//创建没每一个围墙,他们使用的是同一个图片
walls[i] = new JLabel(wallImg);
}
for (int i = 0; i < walls.length; i++) {
//创建没每一个围墙,他们使用的是同一个图片