问候stackoverflow的伟大思想。我最近一直在用java编写一个小型2D游戏,我想将它导出到一个可以在网页上运行的小程序中。我这样做了,代码在作为小程序和应用程序运行时都运行良好。但是,每当我将代码作为小程序运行时,都会显示小的默认小程序窗口,然后会显示另一个具有正确大小的显示内容的窗口。我认为这就是它无法在我的网页上正确显示的原因。我假设它正在显示第一个窗口中的内容,即空窗口。我想知道如何才能使它只显示一个窗口。我正在使用 Canvas 来显示我的窗口。我将上传任何请求的代码。先感谢您!
问问题
231 次
1 回答
1
Java Plug-in 10.5.1.255
Using JRE version 1.7.0_11-b21 Java HotSpot(TM) Client VM
User home directory = C:\Users\Andrew
----------------------------------------------------
c: clear console window
..
0-5: set trace level to <n>
----------------------------------------------------
Attempting to start init...
-INIT METHOD STARTED-
Preferred size set to java.awt.Dimension[width=852,height=480]
Initialized JFrame with size java.awt.Dimension[width=852,height=480]
Initialized screen (284x160)
Initialized keyboard
Added key listener
Resizeable set to false
Title set
Game component added to screen
Frame packed
Exception in thread "AWT-EventQueue-3" java.lang.NullPointerException
at sun.awt.SunToolkit.createImage(Unknown Source)
at com.sun.deploy.uitoolkit.impl.awt.AWTErrorPanel.getErrorImage(Unknown Source)
at com.sun.deploy.uitoolkit.impl.awt.AWTErrorPanel.paintComponent(Unknown Source)
at javax.swing.JComponent.paint(Unknown Source)
at javax.swing.JComponent.paintToOffscreen(Unknown Source)
at javax.swing.RepaintManager$PaintManager.paintDoubleBuffered(Unknown Source)
at javax.swing.RepaintManager$PaintManager.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.prePaintDirtyRegions(Unknown Source)
at javax.swing.RepaintManager.access$700(Unknown Source)
at javax.swing.RepaintManager$ProcessingRunnable.run(Unknown Source)
at java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$200(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.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)
IE 没有小程序,没有窗口。控制台的输出设置为跟踪级别 5。
更新
新结果:
// ..
Frame packed
java.security.AccessControlException: access denied ("java.lang.RuntimePermission" "exitVM.0")
at java.security.AccessControlContext.checkPermission(Unknown Source)
at java.security.AccessController.checkPermission(Unknown Source)
代码(缺少我们只能猜测的 SSCCE)是否随时调用..
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
?
如果是这样,请将其更改为:
// See http://stackoverflow.com/a/7143398/418556 for demo.
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
后者将在沙盒小程序中被允许,而EXIT_ON_CLOSE
即使在受信任的小程序中也是不允许的。
于 2013-01-16T21:28:38.703 回答