zoukankan      html  css  js  c++  java
  • Java 游戏报错 看不懂求教

    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);
    }
    --------------------- 

  • 相关阅读:
    算法学习——贪心篇
    Centos7下搭建LAMP环境,安装wordpress(不会生产博客,只是一名博客搬运工)(菜鸟)
    小白创建网站的曲折之路
    7.2.5 多层嵌套的if语句
    7.2.4 else与if配对
    7.2.3
    7.4 electirc.c -- 计算电费
    oracle数据库命令行查看存储过程
    Linux下如何查看进程准确启动时间
    7.2 if else 语句
  • 原文地址:https://www.cnblogs.com/hyhy904/p/11058035.html
Copyright © 2011-2022 走看看