package com.event;//Window Event
import java.awt.*;
import java.awt.event.*;
public class WindowEventEx extends Frame implements WindowListener{
Label exit;
public WindowEventEx(){
super("WindowEvent 테스트");
exit = new Label("프레임의 종료 버튼을 눌러 주세요");
add(exit);
setBounds(300,300,200,200);
setVisible(true);
addWindowListener(this);
}
public static void main(String[] args){
new WindowEventEx();
}
public void windowClosing(WindowEvent e){
System.exit(0);
}
public void windowActivated(WindowEvent e){}
public void windowClosed(WindowEvent e){}
public void windowDeactivated(WindowEvent e){}
public void windowDeiconified(WindowEvent e){}
public void windowIconified(WindowEvent e){}
public void windowOpened(WindowEvent e){}
}
package com.adapter;
import java.awt.Frame;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
//다중 상속때문에 하나더 클래스 생성
//아답타 클래스를 사용해서 이벤트 처리
class WindowEventHandler extends WindowAdapter{
public void windowClosing(WindowEvent e){
System.exit(0);
}
}
public class WindowEventEx extends Frame{
public WindowEventEx(){
super("이벤트 테스트");
//Frame 이벤트 소스와 WindowAdapter가 상속되어 인벤트를 처리할 수
//있는 객체와 연결
addWindowListener(new WindowEventHandler());
setSize(300,200);
setLocation(100,200);
setVisible(true);
}
public static void main(String[] args) {
new WindowEventEx();
}
}
package com.adapter2;
import java.awt.Frame;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
//다중 상속때문에 하나더 클래스 생성
//아답타 클래스를 사용해서 이벤트 처리
public class WindowEventEx extends Frame{
public WindowEventEx(){
super("이벤트 테스트");
//Frame 이벤트 소스와 WindowAdapter가 상속되어 인벤트를 처리할 수 있는 객체와 연결
//익명 내부 클래스 형태로 이벤트 처리
addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.exit(0);
}
});
setSize(300,200);
setLocation(100,200);
setVisible(true);
}
//멤버 내부 클래스 형태
/*class WindowEventHandler extends WindowAdapter{
}*/
public static void main(String[] args) {
new WindowEventEx();
}
}