Java/2012.04 강좌
16일차 AWT
Bohemian life
2012. 4. 25. 10:43
package com.awtStudy; import java.awt.Frame; import java.awt.event.WindowEvent; import java.awt.event.WindowListener; /* 1.프레임 만든다 * 2.화면에 띄운다. * 3.x누르면 프레임 닫는다. * 4.3번 기능을 프레임에 add * */ public class HelloAWT { static Frame frame; public static void main (String[] args){ frame = new Frame("안녕 프레임"); frame.setSize(200,100); //frame.show(); (지금은 사용하지 않음) --->duplicate frame.setVisible(true); //event - click, drag, double click, touch, 입력 //.addWindowListener (WindowListener 넣기) frame.addWindowListener(new Listener(frame)); } //inner Class를 사용하는 이유: //Outer Class의 Field를 사용 하기 위해서 static class Listener implements WindowListener{ Frame fr; //생성자 메서드 public Listener(Frame f){ fr=f; } @Override //윈도우 창에 x를 누를때 호출 public void windowClosing(WindowEvent e) { frame.dispose();//자원 해제 System.exit(0);//프로세서 강제 종료 시키기 //윈도우가 닫힌다. } @Override 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) {} } }