gpt4 book ai didi

Java 在 JPanel 内声明serialVersionUID 时出错

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

我收到这个错误,这让我从这段脚本中感到非常沮丧......

    JPanel menu = new JPanel() {
private static final long serialVersionUID = 1L;
JTextArea output = new JTextArea(5, 30) {

/**
*
*/
private static final long serialVersionUID = 4714318125998709253L;
this.setEditable(false);
};
JScrollPane scrollPane = new JScrollPane(output);

// public void run() {
// System.out.println("lol");
// JPanel menu = this;
// JButton restart = new JButton("Restart");
// menu.add(restart);
// }

};

我试图在 JTextArea 输出中声明 setEditable...有什么想法吗?

编辑:错误是:

Exception in thread "AWT-EventQueue-0" java.lang.Error: Unresolved compilation problem: 
Syntax error on token ";", < expected

at citadelRPG.Server.createAndShowGUI(Server.java:94)
at citadelRPG.Server.access$0(Server.java:16)
at citadelRPG.Server$1.run(Server.java:162)
at java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$000(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)

出现在声明serialVersionUID的分号上。

最佳答案

声明

this.setEditable(false);

需要位于方法、静态初始值设定项或构造函数中,而不是位于 JTextArea output 的匿名实现的类 block 中。如果您确实希望在 output 类中实现此实现,您可以重写 isEditable

@Override
public boolean isEditable() {
return false;
}

关于Java 在 JPanel 内声明serialVersionUID 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15486053/

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