基本信息
源码名称:java飞机大战(带背景音乐) 游戏原码下载
源码大小:5.75M
文件格式:.rar
开发语言:Java
更新时间:2019-08-28
友情提示:(无需注册或充值,赞助后即可获取资源下载链接)
嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300
本次赞助数额为: 4 元×
微信扫码支付:4 元
×
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
源码介绍
package com.plane.client; import java.awt.Graphics; import java.awt.event.KeyEvent; import java.awt.event.KeyListener; import com.plane.core.Plane; import com.plane.utils.FrameUtil; import com.plane.utils.MusicUtil; import com.plane.utils.MyCanvas; public class PlaneClient extends FrameUtil { MyCanvas canvas; @Override public void initFrame() { canvas = new MyCanvas(); //把面板添加到窗口里 this.add(canvas); //初始化窗口 super.initFrame(); //添加键盘监听 this.addKeyListener(new KeyListener() { @Override public void keyTyped(KeyEvent e) {} @Override public void keyReleased(KeyEvent e) { canvas.plane.keyReleased(e); canvas.keyReleased(e); } @Override public void keyPressed(KeyEvent e) { canvas.plane.keyPressed(e); canvas.keyPressed(e); } }); //启动定时器去刷新面板 new Timer().start(); new Timer_fire().start(); //启动背景音乐播放 new MusicUtil("src/sound/backMusic.mp3").start(); } class Timer extends Thread { @Override public void run() { while(true) { canvas.repaint(); try { Thread.sleep(20); } catch (InterruptedException e) { e.printStackTrace(); } } } } class Timer_fire extends Thread{ public void run() { while (canvas.plane.isFire) { try { canvas.plane.isFire = false; Thread.sleep(1000); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } } public static void main(String[] args) { new PlaneClient().initFrame(); } }