jTextFieldのテキストを他のクラスから変更するにはどうすればよいですか?
クラスAがあり、アイテムを選択して[アカウントの作成]をクリックするとします。jTabbedPaneに同じ名前のタブを追加しました。このタブはクラスBです。このためのコードは次のとおりです。
「アカウントの作成」をクリックすると、この関数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
}
では、jTextField1テキストをクラスAから変更するにはどうすればよいですか。
クラス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で呼び出されています。