title: implementing Action Listener interface
body: <p>the first code prints the string <code>m</code> when <code>m</code> changes,
  but when I remove the first if statement as shown in the second code I am not able to print m when it changes.
  the codes to the program are given below.</p>
  
  <p><strong>code 1</strong></p>
  
  <pre><code> import javax.swing.*;
   import java.awt.*;
   import java.awt.event.*;
      class firstgui extends  JFrame implements ActionListener{
         private JTextArea textarea;
         private JTextField textfield;
  
         static String m="bye";
  
  firstgui() {
      setLayout(new FlowLayout());
      textfield = new JTextField(20);
      add(textfield);
       textarea = new JTextArea(5,20);
       add(textarea);
       textfield.addActionListener(this);         
  }
  public void actionPerformed(ActionEvent e)
  {
      String text= textfield.getText();
      m=text;
      textarea.append("aman: " + text + "\n");
      textfield.setText("");
  }
  
  public static void main(String args[])
  { int t=0; 
      firstgui a = new firstgui();
      a.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      a.setVisible(true);
      a.setTitle("gui");
      a.pack();
      while(true) 
      {
          if(m.equals("bye"))
          {
              System.out.println(m);
          }
          if(!(m.equals("bye")))
              System.out.println(m);
      }       
    }
   }
  </code></pre>
  
  <p><strong>code 2</strong></p>
  
  <pre><code> import javax.swing.*;
   import java.awt.*;
   import java.awt.event.*;
        class firstgui extends  JFrame implements ActionListener{
     private JTextArea textarea;
      private JTextField textfield;
  
      static String m="bye";
  
      firstgui() {
      setLayout(new FlowLayout());
      textfield = new JTextField(20);
      add(textfield);
       textarea = new JTextArea(5,20);
       add(textarea);
       textfield.addActionListener(this);        
  }
  
  public void actionPerformed(ActionEvent e)
  {
      String text= textfield.getText();
      m=text;
      textarea.append("aman: " + text + "\n");
      textfield.setText("");
   }
  
    public static void main(String args[])
   { int t=0; 
      firstgui a = new firstgui();
      a.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      a.setVisible(true);
      a.setTitle("gui");
      a.pack();
      while(true)
      {            
          if(!(m.equals("bye")))
          System.out.println(m);
      }       
    }
   }
  </code></pre>