글쓴이 :이희정 1998년 6월 12일 14:06:38
In Reply to: [질문]버튼을 눌렀을때 이벤트 발생 ..문제.. posted by 해효 on 1998년 6월 12일 10:34:00:
안녕하세요. 이희정입니다.
저도 많이 고민을 하다가 해결한 거라 이렇게 답변을 드리는데...
문제가 있네요...^^;
윈도우의 X 버튼을 눌러서 종료하는 건 같은데...^^;
버튼에서 addActionListener에서 넘겨주는 객체가
뭐가 되어야 하는지를 모르겠네요..^^;
아무리 다 넣어도 에러가 발생해서...
그 부분은 다른 분의 도움을 받으세요.
저는 윈도우의 X 버튼 눌러 종료하는 부분만...^^;
해효님이 자바 1.0x 버전의 함수를 쓰셨길래...
1.1x 대로 변경하였습니다.
도움이 되었으면 좋겠지만... 별 도움이 안되는 것 같네요...^^;
그럼, 좋은 하루되세요. ^_^
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
public class Gui2 extends java.applet.Applet implements ActionListener {
Frame window;
public void init() {
window = new MyFrame("A PopUp Window");
window.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});
window.setSize(400, 300);
window.setVisible(true);
}
class MyFrame extends Frame {
MyFrame(String title) {
super(title);
Panel p = new Panel();
p.setLayout(new FlowLayout());
Button cancel = new Button("Cancel");
cancel.addActionListener(this);
// 이부분에 어떤 객체를 넘겨야 하는지 모르겠네요...^^;
// 어플리케이션이랑 많이 다른가?
// D:\JAVA\java_src\Gui2.java:35: Incompatible type for method.
// Explicit cast needed to convert Gui2. MyFrame to
// java.awt.event.ActionListener.
// cancel.addActionListener(this);
// ^
// 1 error
// 하옇든, 이 부분은 다른 분의 도움을 받으시죠...^^;
// 죄송합니다. 저도 공부한지가 얼마되지 않아서리...^^;
p.add(cancel);
add("South", p);
p.add(new Label("This is a Window",Label.CENTER));
}
}
public void actionPerformed(ActionEvent e) {
if(e.getSource() instanceof Button) {
String label = ((Button)e.getSource()).getLabel();
if (label == "Cancel") {
System.exit(0);
}
}
}
}