一連のパネルを作成するためにカード レイアウトを使用しています。
JFrame クラスを作成しました。そして、このフレームクラスのインスタンスに contentPane を取得し、CardLayout を設定します。この contentPane にすべてのパネルを追加しました。
public class JFrameClass1234 extends javax.swing.JFrame {
public static JFrameClass1234 jFrameInstance1234;
public static JPanelFirstScreen jPanelFirstScreen;
public static JPanelSecondScreen jPanelSecondScreen;
public static JPanelThirdScreen jPanelThirdScreen;
public static JPanelFourthScreen jPanelFourthScreen;
public static JPanelFifthScreen jPanelFifthScreen;
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
jFrameInstance1234 = new JFrameClass1234();
jPanelFirstScreen = new JPanelFirstScreen();
jPanelSecondScreen = new JPanelSecondScreen();
jPanelThirdScreen = new JPanelThirdScreen();
jPanelFourthScreen = new JPanelFourthScreen();
jPanelFifthScreen = new JPanelFifthScreen();
final Container pane = jFrameInstance1234.getContentPane();
pane.add(jPanelFirstScreen,card1);
pane.add(jPanelSecondScreen,card2);
pane.add(jPanelThirdScreen,card3);
pane.add(jPanelFourthScreen,card4);
pane.add(jPanelFifthScreen,card5);
CardLayout cl = (CardLayout)(pane.getLayout());
cl.show(pane, card1);
jFrameInstance1234.setVisible(true);
}
});
}
}//end of class
これで、各パネルの「次へ」または「戻る」ボタンのアクション リスナ内で次のメソッドを呼び出すことで、パネル間を移動できるようになりました。
//For going back to previous panel
private void gotoPreviousPanel() {
final Container pane = JFrameClass1234.jFrameInstance1234.getContentPane();
CardLayout cl = (CardLayout) (pane.getLayout());
cl.show(pane, JFrameClass1234.card1);
JFrameClass1234.JFrameinstance1234.setVisible(true);
}
//For going to next panel
private void gotoNextPanel() {
final Container pane = JFrameClass1234.jFrameInstance1234
.getContentPane();
CardLayout cl = (CardLayout) (pane.getLayout());
cl.show(pane, JFrameClass1234.card3);
JFrameClass1234.jFrameInstance1234.setVisible(true);
}
しかし、パネル間を移動すると、値が保持されます (リセットまたはリロードされません)。パネル間を行ったり来たりするときに、パネルをリセットまたはリロードしたい。または、最初のパネルで選択された「ComboBox」オプションに応じて、2 番目のパネルの「テキストボックス」が表示されたときに常に再読み込みする必要があるとします。これを達成するために誰かが私を助けることができますか???
そのような状況で私が従わなければならない理想的な設計(ロジック)は何ですか?私の状況に固有のドキュメントはありますか? カード レイアウトを使用してフォローしている方法は正しいですか? それ以外の場合は、正しいデザインをお勧めします。
ありがとう、チャンドラ