fenec
fenec

Reputation: 5806

Swing bind a dialog box to a JButton

I am trying to bind a new customer menu dialog box to a newCustomer button in my application. Any ideas?

Upvotes: 0

Views: 1963

Answers (3)

Rickster
Rickster

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

Charlie
Charlie

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

jjnguy
jjnguy

Reputation: 138864

Well to bind actions in java you add ActionListeners.

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

Related Questions