Java 飞机小游戏 报错 看不懂求救

at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$500(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue3.run(UnknownSource)atjava.security.AccessController.doPrivileged(NativeMethod)atjava.security.ProtectionDomain 3.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at java.security.ProtectionDomain3.run(UnknownSource)atjava.security.AccessController.doPrivileged(NativeMethod)atjava.security.ProtectionDomainJavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.awt.EventQueue4.run(UnknownSource)atjava.security.AccessController.doPrivileged(NativeMethod)atjava.security.ProtectionDomain 4.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at java.security.ProtectionDomain4.run(UnknownSource)atjava.security.AccessController.doPrivileged(NativeMethod)atjava.security.ProtectionDomainJavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
Exception in thread “AWT-EventQueue-0” java.lang.NoClassDefFoundError: Could not initialize class Explode
at MyGameFrame.paint(MyGameFrame.java:41)
at MyGameFrame.update(MyGameFrame.java:130)
at sun.awt.RepaintArea.updateComponent(Unknown Source)
at sun.awt.RepaintArea.paint(Unknown Source)
at sun.awt.windows.WComponentPeer.handleEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$500(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue3.run(UnknownSource)atjava.security.AccessController.doPrivileged(NativeMethod)atjava.security.ProtectionDomain 3.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at java.security.ProtectionDomain3.run(UnknownSource)atjava.security.AccessController.doPrivileged(NativeMethod)atjava.security.ProtectionDomainJavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.awt.EventQueue4.run(UnknownSource)atjava.security.AccessController.doPrivileged(NativeMethod)atjava.security.ProtectionDomain 4.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at java.security.ProtectionDomain4.run(UnknownSource)atjava.security.AccessController.doPrivileged(NativeMethod)atjava.security.ProtectionDomainJavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
Exception in thread “AWT-EventQueue-0” java.lang.NoClassDefFoundError: Could not initialize class Explode
at MyGameFrame.paint(MyGameFrame.java:41)
at MyGameFrame.update(MyGameFrame.java:130)
at sun.awt.RepaintArea.updateComponent(Unknown Source)
at sun.awt.RepaintArea.paint(Unknown Source)
at sun.awt.windows.WComponentPeer.handleEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$500(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue3.run(UnknownSource)atjava.security.AccessController.doPrivileged(NativeMethod)atjava.security.ProtectionDomain 3.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at java.security.ProtectionDomain3.run(UnknownSource)atjava.security.AccessController.doPrivileged(NativeMethod)atjava.security.ProtectionDomainJavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.awt.EventQueue4.run(UnknownSource)atjava.security.AccessController.doPrivileged(NativeMethod)atjava.security.ProtectionDomain 4.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at java.security.ProtectionDomain4.run(UnknownSource)atjava.security.AccessController.doPrivileged(NativeMethod)atjava.security.ProtectionDomainJavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)

import java.awt.Color;
import java.awt.Frame;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.util.Date;

public class MyGameFrame extends Frame {

/**
*
*/
private static final long serialVersionUID = 905833189003569926L;
Image planeImg = GameUtil.getImage("images/plane.png");
Image bg = GameUtil.getImage("images/bg.jpg");

Plane plane = new Plane(planeImg,300,150);
Shell[] shells = new Shell[60];

Explode bao ;
Date startTime = new Date();
Date endTime;
int period; //游戏持续的时间

public void paint(Graphics g) { //自动被调用。 g相当于一只画笔
g.drawImage(bg, 0, 0, null);

plane.drawSelf(g);
//画出所有的炮弹
for(int i=0;i<shells.length;i++){
shells[i].draw(g);
//飞机和炮弹的碰撞检测
boolean peng = shells[i].getRect().intersects(plane.getRect());
if(peng){
plane.live = false;
if(bao ==null){
bao = new Explode(plane.x, plane.y);
}
bao.draw(g);
}

//计时
if(!plane.live){
if(endTime==null) {
endTime =new Date();
}
period = (int)((endTime.getTime()-startTime.getTime())/1000);
printInfo(g,"时间:"+period+"秒",40,120,240,Color.BLUE);
}
}
}
public void printInfo (Graphics g,String str, int size, int x,int y,Color color) {
g.setColor(color);
g.getFont();
g.drawString(str, x, y);

}

//重画窗口
class PaintThread extends Thread {
public void run() {
while(true){
repaint(); //重画
try {
Thread.sleep(50);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}

}

//定义键盘监听的内部类
class KeyMonitor extends KeyAdapter {

@Override
public void keyPressed(KeyEvent e) {
plane.addDirection(e);
}

@Override
public void keyReleased(KeyEvent e) {
plane.minusDirection(e);
}

}

public void launchFrame(){
this.setTitle("初作");
this.setVisible(true);
this.setSize(Constant.GAME_WIDTH, Constant.GAME_HEIGHT);
this.setLocation(200, 300);

this.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});

new PaintThread().start(); //启动重画窗口的线程
addKeyListener(new KeyMonitor()); //给窗口增加键盘的监听

//初始化60个炮弹
for(int i=0;i<shells.length;i++){
shells[i] = new Shell();
}

}

public static void main(String[] args) {
MyGameFrame f = new MyGameFrame();
f.launchFrame();
}

private Image offScreenImage = null;

public void update(Graphics g) {
if(offScreenImage == null)
offScreenImage = this.createImage(Constant.GAME_WIDTH,Constant.GAME_HEIGHT);//这是游戏窗口的宽度和高度

Graphics gOff = offScreenImage.getGraphics();
paint(gOff);
g.drawImage(offScreenImage, 0, 0, null);
}
---------------------

Java 游戏报错 看不懂求教的更多相关文章

  1. Python代码报错看不懂?记住这20个报错提示单词轻松解决bug

    1. syntaxerror: invalid syntax语法错误:无效语法 1) syntax [ˈsɪntæks] 语法.句法 2) error [ˈerər] 错误 3) invalid [ɪ ...

  2. Oracle EBS Java Applet报错:找不到类

    Oracle EBS Home Page可以打开,但是无法打开EBS的Form,查看Java控制台,有错误报出. java控制台报错,如下: Java Plug-in 1.6.0_07 使用 JRE ...

  3. android studio java工程 报错

    作者:韩梦飞沙 Author:han_meng_fei_sha 邮箱:313134555@qq.com E-mail: 313134555 @qq.com  android studio java工程 ...

  4. Centos7 JDK安装过程中 解决java -version 报错: bash: /home/jdk1.8.0_161/bin/java: Permission denied

    1.执行Linux命令 -----vim /etc/profile  编辑profile  文件,在里面添加: #set java enviroment JAVA_HOME=/opt/JavaHome ...

  5. debug运行java程序报错

    debug运行java程序报错 ERROR: transport error 202: connect failed: Connection timed out ERROR: JDWP Transpo ...

  6. java @override 报错处理

    转载自:http://blog.sina.com.cn/s/blog_9c7605530101kl9r.html 一.java @override 报错处理 做项目的时候,同事那边电脑上编译通过的ja ...

  7. php通过JavaBridge调用Java类库和不带包的自定义java类成功 但是调用带包的自定义Java类报错,该怎么解决

    php通过JavaBridge调用Java类库和不带包的自定义java类成功 但是调用带包的自定义Java类报错,Class.forName("com.mysql.jdbc.Driver&q ...

  8. Centos 7 JDK验证 解决java -version 报错: bash: /home/jdk1.8.0_161/bin/java: Permission denied

    2.vim /etc/profile  编辑profile  文件,在里面添加: #set java enviroment JAVA_HOME=/usr/java/jdk1.8.0_144 JRE_H ...

  9. Java @override报错的解决方法

    在eclipse中导入工程后@Overide报错 到入工程后,所有的@Override都报如下错误: Multiple markers at this line - The method getCou ...

随机推荐

  1. web.xml配置之<context-param>

    <context-param>的作用和用法: 1.<context-param>配置是是一组键值对,比如: <context-param>        <p ...

  2. AJAX --- 一种创建交互式网页应用的网页开发技术

    目录 AJAX 创建XHR实例 指定readyStatechange事件处理程序 启动请求 发送请求 接收数据 取消XHR请求/响应 AJAX ajax核心技术就是 XMLHttpRequest 对象 ...

  3. python自动化运维-编写rsync+sersync安装脚本实现文件实时同步

    rsync+sersync组合可以实时监听目录的变化,实现实时同步数据. 具体安装教程可查看:http://www.osyunwei.com/archives/7447.html. 安装着实有些复杂, ...

  4. 多线程-threading模块2

    从上面例子中发现线程的创建是颇为麻烦的,每创建一个线程都需要创建一个 t(t1.t2....),如果创建的线程较多时这样极其不方便.下面对通过例子进行改进:   #coding:utf-8 impor ...

  5. Spring MVC访问页面直接显示源码

    转自:https://blog.csdn.net/u011781521/article/details/78751253

  6. Start Developing Mac Apps -- Mac App Store Mac 应用商店

      Mac App Store The information you’ve read so far focused on how to create an app in Xcode. However ...

  7. error: expected ‘)’ before ‘PRId64’(转载)

    转自:www.xuebuyuan.com/2077822.html error: expected ‘)’ before ‘PRId64’ 原来这个宏定义给c用的,C++要用它,就要定义一个__STD ...

  8. python __builtins__ type类 (69)

    69.'type', 返回对象类型 class type(object) | type(object_or_name, bases, dict) | type(object) -> the ob ...

  9. loj#2540. 「PKUWC2018」随机算法

    传送门 完了pkuwc咋全是dp怕是要爆零了-- 设\(f(S)\)表示\(S\)的排列数,\(S\)为不能再选的点集(也就是选到独立集里的点和与他们相邻的点),\(mx(S)\)表示\(S\)状态下 ...

  10. android内存溢出 java.lang.OutOfMemoryError

    今天在做ListView 的时候.想做一个音乐列表模块,前面是图片,后面是分类名称,如下图: 结果运行时候,LogCat是总是报 java.lang.OutOfMemoryError的错误,顾名思义, ...