import java.awt.*;
import java.awt.event.*;
public class KHJ200153077 extends Frame{
String msg;
Checkbox c1,c2;
Button
b;
TextField t1;
TextArea t2;
Panel p;
KHJ200153077(){
setLayout(new
BorderLayout());
p = new Panel();
c1 = new
Checkbox("사과");
c2 = new Checkbox("딸기");
b = new
Button("옙 베베");
t1 = new TextField();
t2 = new
TextArea();
t1.setColumns(15);
t2.setColumns(20);
t2.setRows(20);
b.addActionListener(new
HandleB());
c1.addItemListener(new
HandleC());
c2.addItemListener(new
HandleC());
t1.addActionListener(new
HandleA());
t2.addTextListener(new
HandleT());
addWindowListener(new HandleW());
p.add(c1);
p.add(c2);
p.add(b);
p.add(t1);
add(p,
BorderLayout.NORTH);
add(t2,BorderLayout.CENTER);
}
class HandleB implements
ActionListener{
public void
actionPerformed(ActionEvent
ae){
t2.append(b.getLabel()+"\n");
}
}
class HandleC implements
ItemListener{
public void itemStateChanged(ItemEvent
ie){
if(c1.getState()){ // C1
체크박스가 선택되었다면....
msg =
"체크박스: "+ c1.getLabel()+": ["+c1.getState()+"]"+"\n";
// 그 체크박스의 Label을 반환
}else{
msg
="체크박스: " + c1.getLabel()+ ": [" +c1.getState()+ "]"+ "\n";
}
t2.append(msg);
if(c2.getState()){
msg = "체크박스: " +c2.getLabel()+ ": [ " +c2.getState()+
"]"+ "\n";
}else{
msg = "체크박스: " +c2.getLabel()+ ": ["
+c2.getState() +"]"+ "\n";
}
t2.append(msg);
}
}
class HandleT implements
TextListener{
public void textValueChanged(TextEvent
t){
t2.setText(t2.getText());
}
}
class HandleA implements
ActionListener{
public void
actionPerformed(ActionEvent a){
t2.append(t1.getText()+"\n");
t1.setText("");
}
}
class HandleW extends
WindowAdapter{
public void
windowClosing(WindowEvent we){
System.exit(0);
}
}
public static void main(String args[]){
KHJ200153077 khj =
new KHJ200153077();
khj.setSize(350,300);
khj.show();
}
}
'IT_Programming > Java' 카테고리의 다른 글
StringTokenizer 클래스 (0) | 2007.01.29 |
---|---|
Hastable 클래스 (0) | 2007.01.29 |
스택 클래스 (0) | 2007.01.29 |
예외처리 (0) | 2006.02.27 |
equals() 메소드와 "==" 비교연산자의 차이 (0) | 2006.02.22 |