更改不同类中 JTextField 的文本
我如何从其他类更改 jTextField 的文本
假设我有 A 类,如果我选择一个项目并单击创建帐户。我向 jTabbedPane 添加了一个具有相同名称的选项卡。该选项卡为 B 类。 其代码是:
onclick“创建帐户”此函数addclass(mainCB.getSelectedIndex())已被调用
public void addclass(int a) {
String s=(String) mainCB.getItemAt(a); //mainCB is variable name of combobox
JComponent subpanel2=new B(); //added the class
jTabbedPane1.add(s,subpanel2); //added new tab which is the new class
B ob=new B(); //object of new class B
ob.heading(s); //heading is the function in Class B
}
现在我如何更改A类中的jTextField1文本。B
类中的heading()函数如下:
public void heading(String s){
head.setText(s); //head is the variable name of jTextField1 of class B
}
我有贴出了A班和B班的照片。
这是A班
jTabbedPane 中添加的新面板是 B 类。这在 A 类中被调用。
How can i change the text of a jTextField from other class
Suppose i have Class A in which if i select an item and click create account. I added a tab with same name to my jTabbedPane. This tab is class B.
the code for this is:
onclick on "Create Account" this function addclass(mainCB.getSelectedIndex()) has been called
public void addclass(int a) {
String s=(String) mainCB.getItemAt(a); //mainCB is variable name of combobox
JComponent subpanel2=new B(); //added the class
jTabbedPane1.add(s,subpanel2); //added new tab which is the new class
B ob=new B(); //object of new class B
ob.heading(s); //heading is the function in Class B
}
Now how can i Change the jTextField1 text from class A.
heading() function in class B is as follows:
public void heading(String s){
head.setText(s); //head is the variable name of jTextField1 of class B
}
I have posted the image of both the classes A and B.
This is Class A
The new panel which is added in jTabbedPane is class B. This is being called in class A.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您在
addClass
方法中创建了类B
的两个实例。我认为在subpanel2
(类型为B
)上调用heading
可以解决您的问题。这会是这样的:这是你想要的吗?
You create two instances of the class
B
in youraddClass
method. I think it would solve your problem to callheading
onsubpanel2
, which is of typeB
. This would go something like:Is this what you wanted?