gpt4 book ai didi

java - 为什么我的小程序创建一个单独的窗口

转载 作者:行者123 更新时间:2023-12-01 14:55:12 25 4
gpt4 key购买 nike

问候 stackoverflow 的伟人。我最近正在用java编写一个小型2D游戏,我想将其导出到一个可以在网页上运行的小程序中。我这样做了,代码在作为小程序和应用程序运行时都运行良好。但是,每当我将代码作为小程序运行时,都会显示默认的小小程序窗口,然后会显示另一个以正确大小显示内容的窗口。我认为这就是它无法在我的网页上正确显示的原因。我假设它正在显示第一个窗口(空窗口)的内容。我想知道如何才能只显示一个窗口。我正在使用 Canvas 来显示我的窗口。我将上传任何要求的代码。预先感谢您!

最佳答案

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)

即没有小程序,没有窗口。控制台输出设置为跟踪级别 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 也是不允许的。

关于java - 为什么我的小程序创建一个单独的窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14368112/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com