title: Continuously read from file and do an action
body: <p>I want to continuously read from a text file, and change the color of a box I have shown on the canvas when a certain line is read (the text file is going to be constantly updating). Right now, I have a green square drawn on the canvas and three "test" lines in the text file, and when it reaches the third line of the text file I would like to change the the square to Red.</p>
  
  <p>Here is my code, from two files (myCanvas.java and myFileReader.java). Any point in the right direction is greatly appreciated.</p>
  
  <pre><code>public class myCanvas extends Canvas{
  
      public myCanvas(){
      }
  
      public void paint(Graphics graphics){
          graphics.setColor(Color.green);
          graphics.fillRect(10, 10, 100, 100);
          graphics.drawRect(10,10,100,100);
      }
  
      public static void main(String[] args){
          myCanvas canvas = new myCanvas();
          JFrame frame = new JFrame("Live GUI");
          frame.setSize(400, 400);
          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          frame.getContentPane().add(canvas);
          frame.setVisible(true);
          myFileReader read = new myFileReader();
          read.readFromFile();
          if(myFileReader.strLine == "This is the third line."){
          //change color
          }
  
  }
  
  
  
  public class myFileReader{
      public static String strLine;
  
  public void readFromFile() 
  {
      try{
          FileInputStream fstream = new FileInputStream(System.getProperty("user.dir")+"\\sample.txt");
          DataInputStream in = new DataInputStream(fstream);
          BufferedReader br = new BufferedReader(new InputStreamReader(in));
          while (true){
              strLine = br.readLine();
              if(strLine == null) {
                  Thread.sleep(1000);
              }
          }
          }
      catch (Exception ex){
          System.err.println("Error: " + ex.getMessage());
      }
      }
  }
  </code></pre>