Javaアプリを作成しています。
私は1つのクラスq2a2を持っています。これはjpanelであり、そのデザインは次のように示されています。-img-
コンボボックスからアイテムが選択され、「アカウントの作成」ボタンがクリックされたとします。1つのタブがjTabbedPaneに追加されます。すべてのアイテムに共通のタブがあります。だから私がしたことは、1つのクラスを作成し、ボタンをクリックするたびにそれを追加することです。クラス名はq2a2_addです。こちらもパネルです。このための画像は次のとおりです...
いくつかのアイテムを持っていると、アプリは次のようになります
このためのコードは次のとおりです。
public void addclass(int a) {
if(jTabbedPane1.getTabCount()<13) { //variable name of TabbedPane
String s=(String) mainCB.getItemAt(a); //mainCB is the variable name of main combobox
int dont=0;
for(int j=0;j<tabname.length;j++){ //just to ensure two accounts should not be same
if(s.equals(tabname[j])){
dont=1;
break;
}
}
if(dont==0){
for(int j=0;j<12;j++) {
if(index[j]==0){
q2a2_add subpanel2=new q2a2_add(this); //calling the second class
jTabbedPane1.add(s,subpanel2); //here adding panel
subpanel2.heading(s); // heading() method is defined in q2a2_add() which rename the jTextField to be same as argument s;
tabname[j]=s;
index[j]=1;
break;
}
}
}
else {
JOptionPane.showConfirmDialog(null, (String) mainCB.getItemAt(a)+" is already created","Information", JOptionPane.PLAIN_MESSAGE);
}
}
else {
JOptionPane.showConfirmDialog(null, "Account Overload. Delete wrong account and then create","Caution", JOptionPane.PLAIN_MESSAGE);
}
}
今私の質問はです。関数に見られるように。同じクラスが呼び出されて追加されるたびに。さまざまなタブのさまざまなコンボボックスとテキストボックスにアクセスするにはどうすればよいですか。ユーザーが入力した値を保存して操作したい。たとえば、売掛金、買掛金、事務用品からの入力を異なる方法で読み取る方法などです。
返信してください。