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);
당신은 "입력"버튼 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");
}
});
어떻게? 내가 계산 방법을 ...합시다. 진지하게, 너무 많습니다. 당신은 부모 클래스가'LogIn' 패널에'ActionListener'를 등록하게 할 수 있습니다. 그러나 좀 더 견고한 해결책은 MVC의 일종을 사용하는 것입니다 [예를 들어] (http://stackoverflow.com/questions/26517856/java) -and-gui-do-do-actionlistener-mvc-pattern/26518274 # 26518274) 및 [example] (http://stackoverflow.com/questions/27663306/open-a-jpanel-after- press-a-button-in-a-jframe/27663749 # 27663749) – MadProgrammer
[Observer Pattern] (http://www.oodesign.com/observer-pattern.html) – MadProgrammer
감사합니다. 그 사실을 알지 못했습니다. – user3309479