我需要用JAVA写一个推箱子的小游戏。我有源代码,但是缺少这个小游戏的图片。
导入Java . awt . color;
导入javax . swing . image icon;
导入javax . swing . jframe;
导入javax . swing . jlabel;
导入javax . swing . jpanel;
公共类Txz {
公共静态void main(String[] args) {
JFrame frame = new JFrame("?1.0");//
frame.setBounds(100,20,20 * 48 + 16,14 * 48+38);//λ?ú?С
JPanel panel = new JPanel();//?dos命令:更改文件名
panel . set background(color . red);//
frame . setcontentpane(panel);
panel.setLayout(空);//nonλ?
//
ImageIcon boxImg =新ImageIcon("box2。PNG”);
JLabel box = new JLabel(box img);//?
panel . add(box);
box.setBounds(5 * 48,3 * 48,48,48);
//?
ImageIcon worker img = new ImageIcon(" worker down 2 . png ");
JLabel worker = new JLabel(worker img);
panel . add(worker);
worker.setBounds(8 * 48,8 * 48,48,48);
//
image icon goal img = new image icon(" goal 2 . png ");
JLabel goal = new JLabel(goal img);
panel.add(目标);
goal.setBounds(7 * 48,6 * 48,48,48);
//Χ?
image icon wall img = new image icon(" wall 2。PNG”);
JLabel[]walls = new JLabel[100];
for(int I = 0;我& lt墙壁.长度;i++) {
walls[I]= new JLabel(wall img);
}
int index = 0;//Χ?
for(int I = 0;我& lt20;i++) {
panel . add(walls[index]);
墙壁[索引]。setBounds(i * 48,0,48,48);
index++;
panel . add(walls[index]);
墙壁[索引]。setBounds(i * 48,13 * 48,48,48);
index++;
}
for(int I = 0;我& lt12;i++) {
panel . add(walls[index]);
墙壁[索引]。setBounds(0,(i + 1) * 48,48,48);
index++;
panel . add(walls[index]);
墙壁[索引]。setBounds(19 * 48,(i + 1) * 48,48,48);
index++;
}
for (int i = 0,j = 0;我& lt5;i++,j += 2) {
panel . add(walls[index]);
墙壁[索引]。setBounds((i + 2) * 48,j * 48,48,48);
index++;
}
for (int i = 0,j = 10;我& lt5;i++,j - ) {
panel . add(walls[index]);
墙壁[索引]。setBounds((i + 12) * 48,j * 48,48,48);
index++;
}
//?
frame . set visible(true);
}
}