[ 자바 연습 ]


자바 연습 세번째 awt event 를
이용한 채팅창을 만들어 봅시다.


import java.awt.*;
import java.awt.event.*;

class  TextComponentEventTes extends Frame  {
 
  TextField tf;
  TextArea ta;
 
 TextComponentEventTes(String title){
  super(title);
 
   tf = new TextField();
   ta = new TextArea();
   add(ta, "Center");
   add(tf, "South");

   tf.addActionListener(new ActionListener(){
    public void actionPerformed(ActionEvent e){
     ta.append(tf.getText() + "\n");
     tf.setText("");
     tf.requestFocus();
    }
  });

  ta.setEditable(false);
  setSize(300, 200);
  setVisible(true);
  tf.requestFocus();
 
  addWindowListener(new WindowAdapter(){
    public void windowClosing(WindowEvent evt){
     setVisible(false);
     dispose();
     System.exit(0);
    }
  });


 }
 public static void main(String args[]){
   TextComponentEventTes mainWin =
     new TextComponentEventTes("TextComponentEventTest");

 

 }
}


+ Recent posts