package CHAPTER10;

import java.awt.CardLayout;
import javax.swing.*;

public class C10_10_CardLayoutExample extends JFrame {
	public C10_10_CardLayoutExample() {
		setTitle("CardLayout Example");
		setSize(400, 300);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        // CardLayout과 JPanel 생성
        CardLayout cardLayout = new CardLayout();
        JPanel cardPanel = new JPanel(cardLayout);

        // 카드 1: 첫 번째 화면
        JPanel card1 = new JPanel();
        card1.add(new JLabel("This is the First Card"));
        JButton next1 = new JButton("Go to Second Card");
        card1.add(next1);

        // 카드 2: 두 번째 화면
        JPanel card2 = new JPanel();
        card2.add(new JLabel("This is the Second Card"));
        JButton next2 = new JButton("Go to First Card");
        card2.add(next2);

        // 카드 패널에 카드 추가
        cardPanel.add(card1, "Card1");
        cardPanel.add(card2, "Card2");

        // 버튼 액션 설정
        next1.addActionListener(e -> cardLayout.show(cardPanel, "Card2"));
        next2.addActionListener(e -> cardLayout.show(cardPanel, "Card1"));

        // JFrame에 카드 패널 추가
        add(cardPanel);

        // JFrame 표시
        setVisible(true);
	}
	public static void main(String[] args) {        
		C10_10_CardLayoutExample frame = new C10_10_CardLayoutExample();
        
    }
}
