のJPanelがそれら囲むbeetween CardLayoutに切り替えることができるようにするには:
JPanel cards;
final static String BUTTONPANEL = "Card with JButtons";
final static String TEXTPANEL = "Card with JTextField";
//Where the components controlled by the CardLayout are initialized:
//Create the "cards".
JPanel card1 = new JPanel();
...
JPanel card2 = new JPanel();
...
//Create the panel that contains the "cards".
cards = new JPanel(new CardLayout());
cards.add(card1, BUTTONPANEL);
cards.add(card2, TEXTPANEL);
あなたは "Enter" ボタンにActonListenerを追加する必要があります
JButton enterButton = ...
enterButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
CardLayout cl = (CardLayout)// your reference to the CardLayout here eg. yourJFrame.getContentPane().getLayout();
cl.show(cards, "The name of panel to show, you gave it with the add operation on cardLayout eg. BUTTONPANEL OR TEXTPANEL");
}
});
どのように?私は方法を数えましょう...真剣に、非常に多くがあります。親クラスが 'ActionListener'を' LogIn'パネルに登録させることができますが、もっと頑強な解決策は何らかのMVCを使うことです(例えばhttp://stackoverflow.com/questions/26517856/java)。 (26518274#26518274)と[example](http://stackoverflow.com/questions/27663306/open-a-jpanan-after-and-guide-pre-responselistener-movc-パターンに従う) Press-a-button-in-a-jframe/27663749#27663749) – MadProgrammer
[Observer Pattern](http://www.oodesign.com/observer-pattern.html) – MadProgrammer
ありがとうございました。それを知らなかった。 – user3309479