gpt4 book ai didi

java - 如何在 Java 中将私有(private) Swing 组件变成公共(public) Swing 组件?

转载 作者:行者123 更新时间:2023-12-02 00:29:45 26 4
gpt4 key购买 nike

我想更改 swing 组件(即 jTextArea)的可访问级别,以便我可以在另一个类中访问它!我正在使用 netBeans,但它似乎没有为此目的的视觉功能!这是我尝试过的,但我遇到了一个无法修复的错误

public class HttpHeadersFrame extends javax.swing.JFrame 
{

/** Creates new form HttpHeadersFrame */

public HttpHeadersFrame()
{
initComponents();
}
public JTextArea getRequestTextArea
{
return requestTextArea;//Got error that says "initilizer must be to complete normally"

}

// Variables declaration - do not modify

private javax.swing.JTextArea requestTextArea;
private javax.swing.JTextArea responseTextArea;

最佳答案

应该是

//                                 VV
public JTextArea getRequestTextArea()
{
return requestTextArea;//Got error that says "initilizer must be to complete normally"

}

否则,该 block 将被视为初始化程序,并且内部会出现语法错误。

关于java - 如何在 Java 中将私有(private) Swing 组件变成公共(public) Swing 组件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9306207/

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