论坛首页 Java企业应用论坛

[javase] javax.swing 写的一个坦克大战

浏览 6316 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
   发表时间:2010-01-19  
很早以前写的,现在放上来与大家分享。
这里提供了src目录, 请自己建立工程然后粘进去
运行main包下的main类
呵呵
  • src.rar (6.6 KB)
  • 下载次数: 723
   发表时间:2010-01-19  
大家都在下载,怎么没人提点建议呢????
0 请登录后投票
   发表时间:2010-01-19   最后修改:2010-01-19
下载参观一下:)

Tank类和TankBall类不要用JPanel,用Image. 因为JPanel这类swing组件不是线程安全的,我也是写完了一个小游戏才明白这点。这也是为什么刚玩一会就抛这个Exception的原因。当然你可以写的非常仔细来避免这种问题,但,基本上不太推荐这么做。
引用
Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: No such child: 26
at java.awt.Container.getComponent(Container.java:277)
at javax.swing.JComponent.rectangleIsObscured(JComponent.java:4337)
at javax.swing.JComponent.paint(JComponent.java:1025)
at javax.swing.JComponent.paintToOffscreen(JComponent.java:5122)
at javax.swing.BufferStrategyPaintManager.paint(BufferStrategyPaintManager.java:277)
at javax.swing.RepaintManager.paint(RepaintManager.java:1217)
at javax.swing.JComponent._paintImmediately(JComponent.java:5070)
at javax.swing.JComponent.paintImmediately(JComponent.java:4880)
at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:803)
at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:714)
at javax.swing.RepaintManager.seqPaintDirtyRegions(RepaintManager.java:694)
at javax.swing.SystemEventQueueUtilities$ComponentWorkRequest.run(SystemEventQueueUtilities.java:128)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:597)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)


0 请登录后投票
   发表时间:2010-01-21  
metaphy 写道
下载参观一下:)

Tank类和TankBall类不要用JPanel,用Image. 因为JPanel这类swing组件不是线程安全的,我也是写完了一个小游戏才明白这点。这也是为什么刚玩一会就抛这个Exception的原因。当然你可以写的非常仔细来避免这种问题,但,基本上不太推荐这么做。
引用
Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: No such child: 26
at java.awt.Container.getComponent(Container.java:277)
at javax.swing.JComponent.rectangleIsObscured(JComponent.java:4337)
at javax.swing.JComponent.paint(JComponent.java:1025)
at javax.swing.JComponent.paintToOffscreen(JComponent.java:5122)
at javax.swing.BufferStrategyPaintManager.paint(BufferStrategyPaintManager.java:277)
at javax.swing.RepaintManager.paint(RepaintManager.java:1217)
at javax.swing.JComponent._paintImmediately(JComponent.java:5070)
at javax.swing.JComponent.paintImmediately(JComponent.java:4880)
at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:803)
at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:714)
at javax.swing.RepaintManager.seqPaintDirtyRegions(RepaintManager.java:694)
at javax.swing.SystemEventQueueUtilities$ComponentWorkRequest.run(SystemEventQueueUtilities.java:128)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:597)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)



谢谢,其实我之前写了一个贪吃蛇,运行也是正常的,但偶尔也报错但不影响正常运行,应该也是这个原因吧 呵呵!
0 请登录后投票
   发表时间:2010-01-21  
强悍!  呵呵 继续努力!
0 请登录后投票
   发表时间:2010-02-04  
参观了,简单有效,用GBK编码吧,我这儿一堆乱码。我也在写坦克,不过是3D的,用的JMonkeyEngine.主要不是算法了,关键在于理解API.
0 请登录后投票
   发表时间:2010-02-04  
运行产生了:
Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: No such child: 19
at java.awt.Container.getComponent(Unknown Source)
at javax.swing.JComponent.rectangleIsObscured(Unknown Source)
at javax.swing.JComponent.paint(Unknown Source)
at javax.swing.JComponent.paintToOffscreen(Unknown Source)
at javax.swing.BufferStrategyPaintManager.paint(Unknown Source)
at javax.swing.RepaintManager.paint(Unknown Source)
at javax.swing.JComponent._paintImmediately(Unknown Source)
at javax.swing.JComponent.paintImmediately(Unknown Source)
at javax.swing.RepaintManager.paintDirtyRegions(Unknown Source)
at javax.swing.RepaintManager.paintDirtyRegions(Unknown Source)
at javax.swing.RepaintManager.seqPaintDirtyRegions(Unknown Source)
at javax.swing.SystemEventQueueUtilities$ComponentWorkRequest.run(Unknown Source)
at java.awt.event.InvocationEvent.dispatch(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)
0 请登录后投票
   发表时间:2010-02-04  
这是什么原因,我没有,孤独的坦克在哪里战斗,上面说不要用JPanel,用IMage
0 请登录后投票
   发表时间:2010-02-05  
很不错  要是坦克能好看点九好了  真的无法联想到长那样子
0 请登录后投票
论坛首页 Java企业应用版

跳转论坛:
Global site tag (gtag.js) - Google Analytics