-2

I have to call a method inside the java swing actionperformed method. But when I click the button nothing happens. How to solve this problem?

       private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) 
   {
    hellocalled();
    }
    }
Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
  • 1
    you have to add that `ActionListener` to a button. like `button.addActionListener(yourActionListener);` Post SSCCE – Nikolay Kuznetsov Jan 25 '13 at 07:00
  • Time to do some debugging. Are you sure that the JButton has had the ActionListener added? Have you added println statements in your code to be sure you know what is or isn't being called? Also, please try to format your code better when posting it here. Your code is poorly formatted and difficult to read, and since you're asking volunteers for free help, it's not asking too much for us to request that you don't make it overly difficult to help you. – Hovercraft Full Of Eels Jan 25 '13 at 07:00
  • show us the code for `hellocalled();` method – Abubakkar Jan 25 '13 at 07:01
  • What was the idea of the 5 blank lines in that snippet? Blank lines don't make broken code work. – Andrew Thompson Jan 25 '13 at 07:44

1 Answers1

6

You need to add action listener to your button in order to respond to click event:

Button b = new Button();
b.addActionListener(new ActionListener(){

    public void actionPerformed(ActionEvent evt){
       jButton1ActionPerformed(evt);
       // call the method jButton1ActionPerformed
       // or you can call the one you have defined `hellocalled();` here
    } 
  }
}
Abubakkar
  • 15,488
  • 8
  • 55
  • 83