예제 9월 1일 이벤트 리스너 예제
2009. 9. 1. 10:56
package net.jeongsam.gui; import java.awt.Button; import java.awt.FileDialog; import java.awt.FlowLayout; import java.awt.Frame; import java.awt.event.*; @SuppressWarnings("serial") class EventEx02 extends Frame implements ActionListener, WindowListener { Button b1, b2; public EventEx02() { super("File Dialog Sample"); b1 = new Button("파일 대화 상자 생성 버튼"); b2 = new Button("종료 버튼"); b1.addActionListener(this); b2.addActionListener(this); setLayout(new FlowLayout(FlowLayout.CENTER)); add(b1); add(b2); addWindowListener(this); setSize(400, 300); setVisible(true); } public void actionPerformed(ActionEvent e) { if (e.getSource() == b1) { FileDialog fdia = new FileDialog( this, "열기 대화창에 온 것을 환영합니다.", FileDialog.LOAD); fdia.setVisible(true); b1.requestFocus(); } if (e.getSource() == b2) { dispose(); System.exit(0); } } @Override public void windowActivated(WindowEvent arg0) { // TODO Auto-generated method stub } @Override public void windowClosed(WindowEvent arg0) { // TODO Auto-generated method stub } @Override public void windowClosing(WindowEvent arg0) { dispose(); System.exit(0); } @Override public void windowDeactivated(WindowEvent arg0) { // TODO Auto-generated method stub } @Override public void windowDeiconified(WindowEvent arg0) { // TODO Auto-generated method stub } @Override public void windowIconified(WindowEvent arg0) { // TODO Auto-generated method stub } @Override public void windowOpened(WindowEvent arg0) { // TODO Auto-generated method stub } /** * @param args */ public static void main(String[] args) { new EventEx02(); } }