新しい顧客メニューダイアログボックスをアプリケーションのnewCustomerボタンにバインドしようとしています。何か案は?
1878 次
3 に答える
2
Javaでアクションをバインドするには、ActionListener
sを追加します。
ボタンを作成するときは、ActionListenerを追加する必要があります。そうすれば、クリックイベントが発生したときに、ボタンは何をすべきかを認識します。
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.
}
});
于 2009-06-05T18:18:22.183 に答える
0
私の知る限り、Componentから継承されるadd()メソッドはいくつかありますが、いずれもActionListenerをJButtonに追加しません。代わりにaddActionListener()を意味しますか?
于 2009-06-05T18:41:22.800 に答える
0
JButton newCustomer = new JButton();
newCustomer.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
// TODO bind the new customer menu dialog box
}
});
于 2009-06-10T21:19:41.517 に答える