1 Reply Latest reply: Dec 18, 2013 2:05 PM by 1012252 RSS

    Java - ActionListener on Button

    1012252

      Hi,

       

      I am trying to add listener to my button in my applet although I am facing a problem. Namely my applet structure looks as follow;

       

      public class GUI extends JApplet implements ActionListener {

        private JButton jButtonCalculate;

       

        private ActionListener calculateButtonListener = new ActionListener()

        {

             public void actionPerformed(ActionEvent e)

             {

                  if (e.getSource() != jButtonCalculate) {

                  //DO SOMETHING

                  }

             }

        };

       

        public void init() {

        jButtonCalculate.addActionListener(calculateButtonListener);

        }

       

      The listener for button is not working without putting the below code above the public void init():

      public GUI() {

            init();

      }

       

      Could somebody tell me how to add listener to my button without the above change as after including it to my applet the listener is working although my InputVerifier method will be not working. I will be appreciate for your suggestions

       

      Thanks in advance