자바 이벤트 질문!!!
치킨마루
import java.awt.*;
import java.awt.event.*;
public class TextComponentEventTest extends Frame {
TextField tf;
TextArea ta;
TextComponentEventTest(String title)
{
super(title);
tf = new TextField();
ta = new TextArea();
add(ta,Center);
add(tf,South);
tf.addActionListener(new EventHandler());
addWindowListener(new EventHandler());
ta.setEditable(false);
setSize(300,200);
setVisible(true);
tf.requestFocus();
}
public static void main(String[] args) {
TextComponentEventTest t = new TextComponentEventTest(dd);
}
class EventHandler extends WindowAdapter implements ActionListener{
public void actionPerformed(ActionEvent e){
ta.append(tf.getText()+\n);
tf.setText();
tf.requestFocus();
}
public void windowClosing(WindowEvent e)
{
e.getWindow().setVisible(false);
e.getWindow().dispose();
System.exit(0);
}
}
}
여기에서 보면 이벤트를 해줄때 extends WindowAdapter implements ActionListener 이걸써서 저 함수들을
쓸수 있게 된거자나요
import java.awt.*;
import java.awt.event.*;
public class CheckboxEventTest extends Frame {
Label q1;
Label q2;
Label score;
Checkbox q1cb1,q1cb2,q1cb3,q1cb4;
Checkbox q2cb1,q2cb2,q2cb3,q2cb4;
CheckboxGroup group;
Button end;
CheckboxEventTest(String title)
{
super(title);
setSize(500,300);
setLayout(new GridLayout(13,1));
q1 = new Label(1.호출되는경우 모두골라);
q1cb1 = new Checkbox(버튼);
q1cb2 = new Checkbox(엔터키);
q1cb3 = new Checkbox(메뉴아이템);
q1cb4 = new Checkbox(더블클릭);
q2 = new Label(2. 프레임기본매니저 하나만);
group = new CheckboxGroup();
q2cb1 = new Checkbox(f,group,false);
q2cb2 = new Checkbox(g,group,false);
q2cb3 = new Checkbox(M,group,false);
q2cb4 = new Checkbox(c,group,false);
score = new Label(결과);
end = new Button(결과 고고);
end.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
float total=0;
if(q1cb1.getState()) total += 12.5;
if(q1cb2.getState()) total += 12.5;
if(q1cb3.getState()) total += 12.5;
if(q1cb4.getState()) total += 12.5;
if(q2cb3.getState()) total += 50;
score.setText(너의 점수는 + total);
}
});
addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
e.getWindow().setVisible(false);
e.getWindow().dispose();
System.exit(0);
}
});
add(q1);
add(q1cb1); add(q1cb2); add(q1cb3); add(q1cb4);
add(new Label());
add(q2);
add(q2cb1); add(q2cb2); add(q2cb3); add(q2cb4);
add(end);
add(score);
setVisible(true);
}
public static void main(String[] args) {
// TODO Auto-generated method stub
CheckboxEventTest mainWin = new CheckboxEventTest(qq);
}
}
근데 이벤트 처리를 저렇게 했을때 저기는 extends WindowAdapter implements ActionListener 이런걸 해주지 않았는데
어떻게 쓸수가 있는건지 설명좀해주세요 자세히 ㅠㅠ