자바 액션리스너 사용 4가지 방법 (4)

814 단어 자바자바
package 액션리스너_4가지_유형;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;

@SuppressWarnings("serial")
class MyFrame4 extends JFrame{
	JPanel panel;
	JButton button;
	
	MyFrame4(){
		setTitle("이벤트 예제");
		setSize(300, 200);
		
		panel = new JPanel();
		button = new JButton("버튼을 누르시오");
		
		button.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				JButton button = (JButton) e.getSource();
				if(e.getSource() == button){
					button.setText("이벤트 발생");
				}
			}
		});
		
		panel.add(button);
		add(panel);
		setVisible(true);
	}
}

public class Lt4 {
	public static void main(String[] args) {
		new MyFrame4();
	}
}

좋은 웹페이지 즐겨찾기