title: ActionListener for multiple buttons-Swing
body: <pre><code>public class string implements ActionListener{
  
      JLabel jlab;
  
      public void actionPerformed(ActionEvent Ae){
           jlab.setText(Ae.getActionCommand());
       }
  
          public static void main(String args[]){
              JFrame j = new JFrame("HP");
              j.setSize(300,300);
              j.setLayout(new FlowLayout());
              j.setDefaultCloseOperation(j.EXIT_ON_CLOSE);
              j.setVisible(true);    
  
          jlab=new JLabel("Here");
          j.add(jlab);
  
              JButton j1=new JButton("Button1");
              j1.setActionCommand("Your pressed Button 1");
  
              j1.addActionListener(this );
  
              j.add(j1);
  
              JButton j2=new JButton("Button2");
              j2.setActionCommand("Your pressed Button 1");
              j2.addActionListener(this );
              j.add(j2);
      }
     }
  </code></pre>
  
  <p>I want to handle the actions of multiple buttons using the same EventHandler. When the buttons are clicked, the text of the label would be changed accordingly.</p>
  
  <p>This code is showing the error that </p>
  
  <pre><code>Non static variable this cannot be referenced from a static context. 
  </code></pre>
  
  <p>How can I rectify this code?</p>