【发布时间】:2014-04-03 09:27:28
【问题描述】:
我是 Java 新手,但遇到了难题。我想从另一个类访问 GUI 组件(已在一个类中创建)。我正在从一个类创建一个新的 GUI 类,就像这样;
GUI gui = new GUI();
我可以访问那个类中的组件,但是当我去另一个类时我不能。我真的只需要访问JTextAreas 来更新他们的内容。请有人指出我正确的方向,非常感谢任何帮助。
GUI类:
public class GUI {
JFrame frame = new JFrame("Server");
...
JTextArea textAreaClients = new JTextArea(20, 1);
JTextArea textAreaEvents = new JTextArea(8, 1);
public GUI()
{
frame.setLayout(new FlowLayout(FlowLayout.LEADING, 5, 3));
...
frame.setVisible(true);
}
}
【问题讨论】:
-
如何将所需的对象(可能在列表或其他东西中)传递给需要访问它们的类(通过该类的构造函数)?
标签: java swing user-interface