Reputation: 5806
I am trying to bind a new customer menu dialog box to a newCustomer button in my application. Any ideas?
Upvotes: 0
Views: 1963
Reputation: 220
JButton newCustomer = new JButton();
newCustomer.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
// TODO bind the new customer menu dialog box
}
});
Upvotes: 0
Reputation: 216
As far as I know, there are several add() methods which are inherited from Component, but none of which will add an ActionListener to a JButton. Do you mean addActionListener() instead?
Upvotes: 0
Reputation: 138864
Well to bind actions in java you add ActionListener
s.
When constructing your button you need to add an ActionListener to it. That way, when the click event happens, the button knows what to do.
newCustomerButon.add(new ActionListener(){
public void actionPerformed(ActionEvent e){
// This is where you put the code for popping up the form.
yourForm.setVisible(true); // Or something similar.
}
});
Upvotes: 2