package CHAPTER11;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;

//메인 JFrame 클래스
public class C11_07_LambdaClassEvent extends JFrame {
	public C11_07_LambdaClassEvent() {

		setTitle("숫자 카운트 프로그램");
		setSize(300, 200);
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setLayout(null);

		JLabel label = new JLabel("Count: 0");
		label.setBounds(100, 50, 100, 30);
		add(label);

		JButton button = new JButton("Click Me");
		button.setBounds(100, 100, 100, 30);

		// 람다식을 사용한 이벤트 처리
		final int[] counter = { 0 }; // 람다식에서 사용하기 위해 배열로 선언
		button.addActionListener(e -> {
			counter[0] = (counter[0] % 100) + 1; // 1~100 순환
			label.setText("Count: " + counter[0]);
		});
		add(button);
		setVisible(true);
	}

	public static void main(String[] args) {
		C11_07_LambdaClassEvent app = new C11_07_LambdaClassEvent();
	}
}
