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.EventQueue 3. r u n ( U n k n o w n S o u r c e ) a t j a v a . s e c u r i t y . A c c e s s C o n t r o l l e r . d o P r i v i l e g e d ( N a t i v e M e t h o d ) a t j a v a . s e c u r i t y . P r o t e c t i o n D o m a i n 3.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at java.security.ProtectionDomain 3.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.EventQueue 4. r u n ( U n k n o w n S o u r c e ) a t j a v a . s e c u r i t y . A c c e s s C o n t r o l l e r . d o P r i v i l e g e d ( N a t i v e M e t h o d ) a t j a v a . s e c u r i t y . P r o t e c t i o n D o m a i n 4.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at java.security.ProtectionDomain 4.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.EventQueue 3. r u n ( U n k n o w n S o u r c e ) a t j a v a . s e c u r i t y . A c c e s s C o n t r o l l e r . d o P r i v i l e g e d ( N a t i v e M e t h o d ) a t j a v a . s e c u r i t y . P r o t e c t i o n D o m a i n 3.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at java.security.ProtectionDomain 3.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.EventQueue 4. r u n ( U n k n o w n S o u r c e ) a t j a v a . s e c u r i t y . A c c e s s C o n t r o l l e r . d o P r i v i l e g e d ( N a t i v e M e t h o d ) a t j a v a . s e c u r i t y . P r o t e c t i o n D o m a i n 4.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at java.security.ProtectionDomain 4.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.EventQueue 3. r u n ( U n k n o w n S o u r c e ) a t j a v a . s e c u r i t y . A c c e s s C o n t r o l l e r . d o P r i v i l e g e d ( N a t i v e M e t h o d ) a t j a v a . s e c u r i t y . P r o t e c t i o n D o m a i n 3.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at java.security.ProtectionDomain 3.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.EventQueue 4. r u n ( U n k n o w n S o u r c e ) a t j a v a . s e c u r i t y . A c c e s s C o n t r o l l e r . d o P r i v i l e g e d ( N a t i v e M e t h o d ) a t j a v a . s e c u r i t y . P r o t e c t i o n D o m a i n 4.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at java.security.ProtectionDomain 4.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);
}

}

  • 5
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 13
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 13
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值