title: How to update the JTextField when the variable value is changed?
body: <p>I have two <code>Java(.java) files</code>. One has a <code>JButton</code> and <code>JTextField</code> and the other has a <code>Thread</code>. In first <code>Java file</code>, I have added an <code>ActionListener</code> to the <code>JButton</code> so that, when the button is pressed, a thread (object for 2nd .java file in created and thread is initiated) runs which modifies an integer variable continuously. How to display the value of that integer variable (of 2nd .java file) in the <code>JTextField</code> (of 1st .java file) ?</p>
  
  <p>Detection.java </p>
  
  <pre><code>package sample;
  public class Detection implements Runnable
  {
      public String viewers;
      public int count;
      public void run() 
      {                         
          try 
          {
              while (true) 
              {
                  // i have written code for displaying video.
                  // and it say how many no. of people in the video 
                  // the no of people is stored in a variable "count"
  
                  viewers=""+count; //storing count as string so as to display in the JTextField
              }           
          }                
          catch (Exception e)
          {
              System.out.println("Exception: "+e);
          }
      }
  }
  </code></pre>
  
  <p>UsrInterfac.java </p>
  
  <p>//build using WindowBuilder eclipse juno</p>
  
  <pre><code>package sample;
  import java.awt.EventQueue;    
  import javax.swing.JFrame;   
  import javax.swing.JButton;    
  import javax.swing.JTextField;    
  import java.awt.event.ActionListener;    
  import java.awt.event.ActionEvent;    
  
  public class UsrInterfac 
  {    
      private JFrame frame;
      private JTextField textField;
      Detection dd = new Detection();
      Thread th = new Thread(dd);
  
      /**
       * Launch the application.
       */
      public static void main(String[] args) 
      {
          EventQueue.invokeLater(new Runnable() 
          {
              public void run() 
              {
                  try 
                  {
                      UsrInterfac window = new UsrInterfac();
                      window.frame.setVisible(true);
                  } 
                  catch (Exception e) 
                  {
                      e.printStackTrace();
                  }
              }
          });
      }
  
      /**
       * Create the application.
       */
      public UsrInterfac() 
      {
          initialize();
      }
  
      /**
       * Initialize the contents of the frame.
       */
      private void initialize() 
      {
          frame = new JFrame();
          frame.setBounds(100, 100, 450, 300);
          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          frame.getContentPane().setLayout(null);
  
          JButton btnStartThread = new JButton("Start Thread");
          btnStartThread.addActionListener(new ActionListener() 
          {
              public void actionPerformed(ActionEvent arg0) 
              {               
                  th.start();                 
              }
          });
          btnStartThread.setBounds(59, 133, 117, 23);
          frame.getContentPane().add(btnStartThread);
  
          textField = new JTextField();
          textField.setBounds(270, 134, 104, 20);
          frame.getContentPane().add(textField);
          textField.setColumns(10);
      }
  }
  </code></pre>