import java.applet.Applet;
import java.awt.*;

public class ThreadDemo extends Applet implements Runnable {

        TextField Title,PresentCount;
        int count=0;
        String TitleString;
        Button but;
        Thread ThisThread=null;
        Thread OtherThread=null;
        boolean first_time=true;


    public void init() {
        ThisThread=Thread.currentThread();
         but =new Button("Count_up");
        Title=new TextField();

 // "The Applet panel"
System.out.println(ThisThread.toString());
        setLayout(new BorderLayout());
        add("North",Title);
        add("Center",but);
        Title.setText("The Count is "+count);
    }
    public void start(){
      if(OtherThread==null){
        OtherThread=new Thread(this,"A_New_Thread");
        OtherThread.start();
        }

    }


    synchronized public void run(){
        while(true){
            System.out.println(Thread.currentThread().toString());
            try{ wait();}
               catch(InterruptedException e){}
            Title.setText("The Count is "+count);
        }
    }




        synchronized public boolean action(Event evt, Object obj) {
            if (evt.target instanceof Button){
                    System.out.println(Thread.currentThread().toString());
                    count++;
                    notify();
              }
             return true;
         }

  }//end of class