gpt4 book ai didi

java - JFrame 构造函数在生成的代码中失败

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

为我的窗口启动线程的简化代码:

public static LiDrThread lidrThread;
public void onKeyInput(InputEvent.KeyInputEvent event){
if( lidrThread== null || !lidrThread.isAlive())
{
lidrThread= new LiDrThread();
lidrThread.start();
}
}

重写我的 LiDrThread 类中的 run 方法,它扩展了 Thread

private LightDrafterWindow window;
@Override
public void run() {
try {
LogHelper.info("Initializing window");
window = new LightDrafterWindow();
LogHelper.info("Setting window Visible");
window.setVisible(true); // altered since original post
} catch (Exception e) {
LogHelper.warn("Window failed to open");
e.printStackTrace();
}
}

这是我的构造函数的精简代码,我的窗口扩展了 JFrame:

public JPanel contentPane;
public LightDrafterWindow() {
LogHelper.info("Accessing PlayerName");
LogHelper.info("Accessing Player Capabilities");

LogHelper.info("Setting up basics of Window");
//setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // line 48
setBounds(100, 100, 450, 300);
contentPane = new JPanel();
setContentPane(contentPane);
contentPane.setLayout(null);

//PlayerInfo section -----------------------------------------------------------------------------------------------
LogHelper.info("Initializing player info panel");
contentPane.setVisible(true);
}

最后一个 LogHelper 之后还有更多内容,但这是我的控制台中显示的内容:

[18:12:46] [Thread-15/INFO] [lidr]: Initializing window
[18:12:46] [Thread-15/INFO] [lidr]: Accessing PlayerName
[18:12:46] [Thread-15/INFO] [lidr]: Accessing Player Capabilities
[18:12:46] [Thread-15/INFO] [lidr]: Setting up basics of Window
[18:12:46] [Thread-15/WARN] [lidr]: Window failed to open
[18:51:14] [Thread-15/INFO] [STDERR]: [main.java.lidr.thread.LiDrThread:run:23]: java.lang.ArrayIndexOutOfBoundsException: 5
[18:51:14] [Thread-15/INFO] [STDERR]: [main.java.lidr.thread.LiDrThread:run:23]: at net.minecraftforge.fml.relauncher.FMLSecurityManager.checkPermission(FMLSecurityManager.java:21)
[18:51:14] [Thread-15/INFO] [STDERR]: [main.java.lidr.thread.LiDrThread:run:23]: at java.lang.SecurityManager.checkExit(Unknown Source)
[18:51:14] [Thread-15/INFO] [STDERR]: [main.java.lidr.thread.LiDrThread:run:23]: at javax.swing.JFrame.setDefaultCloseOperation(Unknown Source)
[18:51:14] [Thread-15/INFO] [STDERR]: [main.java.lidr.thread.LiDrThread:run:23]: at main.java.lidr.thread.LightDrafterWindow.<init>(LightDrafterWindow.java:48)
[18:51:14] [Thread-15/INFO] [STDERR]: [main.java.lidr.thread.LiDrThread:run:23]: at main.java.lidr.thread.LiDrThread.run(LiDrThread.java:18)

此时我不确定会出现什么问题。它似乎在生成的代码上失败了,我只是对 Gui 的了解不够,看不出有什么问题。

如果你想查看更多代码,我有这个项目 github

编辑------------注释掉导致此错误的行后,没有其他任何东西导致错误,但是 jframe 仍然没有显示。更新了代码以反射(reflect)更改。

最佳答案

问题来自 Forge 代码内部。里面有代码可以防止任何类调用系统退出。

解决方案是使用 DISPOSE_ON_CLOSE。

关于java - JFrame 构造函数在生成的代码中失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36024290/

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