import java.awt.CardLayout; import javax.swing.JButton; import javax.swing.JFrame; public class MainWindow extends JFrame { JButton button1 = new JButton("gomb1"); JButton button2 = new JButton("gomb2"); JButton button3 = new JButton("gomb3"); CardLayout card = new CardLayout(50, 100); public MainWindow() { this.button1.addActionListener(e->onClickButton()); this.button2.addActionListener(e->onClickButton()); this.button3.addActionListener(e->onClickButton()); this.setLayout(card); this.add(button1); this.add(button2); this.add(button3); this.setTitle("CardLayout"); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.pack(); this.setVisible(true); } private void onClickButton() { this.card.next(this.getContentPane()); } }