Day 1:窗口绘制并导入背景图片
public class mygame extends JFrame {bj b=new bj();void launch() throws InterruptedException {this.setVisible(true);//设置窗口是否显示this.setSize(728,624);//设置窗口宽高this.setLocationRelativeTo(null);//设置界面是否默认居中打开this.setTitle("我的小游戏");//设置标题setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);//设置关闭方式}public void paint(Graphics g){b.paintself(g);}public static void main(String[] args) throws InterruptedException {mygame mg=new mygame();mg.launch();}}
背景类设置:
public class bj {Image bg1=Toolkit.getDefaultToolkit().getImage("image/bg.jpg");Image bg2=Toolkit.getDefaultToolkit().getImage("image/bg1.jpg");Image bg3=Toolkit.getDefaultToolkit().getImage("image/peo.png");void paintself(Graphics g){g.drawImage(bg2,0,0,null);g.drawImage(bg1,0,200,null);g.drawImage(bg3,310,50,null);}}
最终效果:
如果觉得《JAVA小游戏——黄金矿工》对你有帮助,请点赞、收藏,并留下你的观点哦!