-1

I'm trying to create a button event by implementing an ActionListener thorugh a class, but I'm getting an error when I try to register my button with an ActionListener. The error reads "non static varaible this cannot be referenced from static context".

public  class TestProjects implements ActionListener {
    public static void main(String[] args) {
        Frame f = new Frame();
       final TextField tf = new TextField();
       tf.setBounds(50,50,150,20);
       Button b = new Button("Click Here");
       b.setBounds(50, 100,60,30);
       b.addActionListener(this);
       f.add(b); f.add(tf);
       f.setSize(400,400);
       f.setLayout(null);
       f.setVisible(true);
    }

    @Override
    public void actionPerformed(ActionEvent ae)
    {
     tf.setText("Welcome to my App");    
    }

}

0 Answers0