Notice
Recent Posts
Recent Comments
Link
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | 5 | 6 | |
| 7 | 8 | 9 | 10 | 11 | 12 | 13 |
| 14 | 15 | 16 | 17 | 18 | 19 | 20 |
| 21 | 22 | 23 | 24 | 25 | 26 | 27 |
| 28 | 29 | 30 | 31 |
Tags
- Graphic
- 메서드
- Spring
- Eclips
- oracle
- layout
- OGNL
- 생성자
- 배열
- HTML
- Android
- 국제화
- mybatis
- 기본
- struts2
- 오버로딩
- Java
- 메소드
- 예외처리
- JavaScript
- 클래스
- 안드로이드
- 전화걸기
- AWT
- 이클립스
- 어노테이션
- 에러페이지
- paint
- JSP
- Menu
Archives
- Today
- Total
note
Window Event 본문
인터페이스 구현 -> 내부 클래스 아답터 상속 -> 익명 내부클래스로 호출

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();
}
}
'자바 > AWT' 카테고리의 다른 글
| Graphic Font (0) | 2011.12.29 |
|---|---|
| Adapter Ex (0) | 2011.12.29 |
| Mouse Motion (0) | 2011.12.29 |
| Key Event (0) | 2011.12.29 |
| Iteam Event (0) | 2011.12.29 |