package thread;
import java.awt.*;
import java.awt.event.*;

class myObject {
  boolean waitFlag=false;

  public void myWait(){
    if(waitFlag)
      try{
        this.wait();
      }
    catch(InterruptedException e) {

    }
  }
  public void myNotify(){
    this.notify();
  }

}
public class myThreadFrame extends Frame implements ActionListener{
  TextArea tx = new TextArea(10, 30);
  Button b = new Button("스레드 중지");
  public myThreadFrame() {
    add(tx, BorderLayout.CENTER);
    add(b, BorderLayout.SOUTH);
    b.addActionListener(this);
    setSize(400, 400);
    setVisible(true);
    Thread th1 = new myThread("Kitae");
    th1.start();
    Thread th2 = new myThread("Hansung");
    th2.start();
  }
  public void actionPerformed(ActionEvent e){
    if(e.getActionCommand().equals("스레드 중지")){

    }
  }
  class myThread extends Thread{
  public myThread(String name) {
    super(name);
  }
  synchronized public void setText(int i) {
    String s =tx.getText()+this.getName()+i+" running\n";
    tx.setText(s);
  }
  public void run() {
    for(int i=0; i<10; i++){
//       ob.myWait();
       setText(i);
       try{
        this.sleep(1000);
       }
       catch(InterruptedException e) {}
      }
    }
  }

  public static void main(String[] args) {
    myThreadFrame myThreadFrame1 = new myThreadFrame();
  }
}
