package com.lyc;
import javax.swing.*;
import java.awt.*;
public class TXZ {
public static void main(String[] args) {
//类名 对象名
JFrame gameJFrame = new JFrame();
//设置标题
gameJFrame.setTitle("推箱子1.0");
//窗口尺寸
gameJFrame.setSize(22 * 48 + 10, 12 * 48 + 30);
//gameJFrame.setLocation();
//gameJFrame.setBounds();
//居中
gameJFrame.setLocationRelativeTo(null);
//退出窗口且关闭,结束程序
gameJFrame.setDefaultCloseOperation(3);
//创建面板
JPanel panel = new JPanel();
//对象名。属性名 普通属性
//类名。静态名 静态属性
panel.setBackground(Color.PINK);
//设置布局为自定义布局
panel.setLayout(null);
//内容面板 设置面板与窗体相关联
gameJFrame.setContentPane(panel);
//创建图片对象,构造方法传参,设置图片路径
ImageIcon boxImg = new ImageIcon("imgs/box3.png");
//创建标签,构造方法传参,把图片放入标签
JLabel box = new JLabel(boxImg);
//把标签放入面板
panel.add(box);
box.setBounds(3*48,3*48,48,48);
ImageIcon workImg = new ImageIcon("imgs/workerDown3.png");
JLabel worker = new JLabel(workImg);
panel.add(worker);
worker.setBounds(4*48,3*48,48,48);
ImageIcon goalImg = new ImageIcon("Imgs/goal3.png");
JLabel goal = new JLabel(goalImg);
panel.add(goal);
goal.setBounds(5*48,7*48,48,48);
//添加围墙
ImageIcon wallImg =new ImageIcon("imgs/wall3.png");
JLabel[] walls = new JLabel[22*2+(12-2)*2];
for (int i =0;i<walls.length;i++){
walls[i] = new JLabel(wallImg);
}
int index = 0;
for(int i = 0;i<22;i++){
panel.add(walls[index]);
walls[index++].setBounds(i*48,0,48,48);
panel.add(walls[index]);
walls[index++].setBounds(i*48,11*48,48,48);
}
for(int i =1;i<=10;i++){
panel.add(walls[index]);
walls[index++].setBounds(0,i*48,48,48);
panel.add(walls[index]);
walls[index++].setBounds(21*48,i*48,48,48);
}
//窗体可见
gameJFrame.setVisible(true);
}
}
01-14
1281
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
12-09
9506
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
08-28