When I clicked a component for instance a button, the event handler code as in below appears under Source tab. Could anyone please explain to me how it works and why does the action_Performed method appear two times, once by itself as a method and then another time under a class unknown to me called actionAdapter? All I want to do is just code one event handler that handles all button clicks, like so:
public void button_actionPerformed(ActionEvent e, Object arg);
{ ...... etc }
Here's theh code generated by JBuilder when I double-clicked a button:
public void jButton10_actionPerformed(ActionEvent e) {
}
}
class Frame2_jButton10_actionAdapter implements ActionListener {
private Frame2 adaptee;
Frame2_jButton10_actionAdapter(Frame2 adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton10_actionPerformed(e);
}
}
Thanks in advance for explaining to me.
I also found out from Sun website that ActionListener does not have an adapter class. So why is the a declaration of this class in the event handler code?
class Frame2_jButton10_actionAdapter implements ActionListener { //etc }
Here's the link that says so: class
http://java.sun.com/docs/books/tutorial/uiswing/events/api.html
>Could anyone please explain to me how it works and why does the
>action_Performed method appear two times, once by itself as a method and
>then another time under a class unknown to me called actionAdapter?
In order for the button to have any effect, you have to register an
ActionListener object with the button. The JBuilder code is generating an
ActionListener, which it then registers with the button (look in the
jbInit() method for that code), and then provides a callout from the
ActionListener back to your Frame class to do the real work.
--
Kevin Dean [TeamB]
Dolphin Data Development Ltd.
http://www.datadevelopment.com/
Please see Borland's newsgroup guidelines at
http://info.borland.com/newsgroups/guide.html
JButton2 jButton2 = new JButton();
jButton2.setBackground(Color.pink);
jButton2.setBounds(new Rectangle(100, 188, 85, 32));
jButton2.setFont(new java.awt.Font("Dialog", 1, 14));
jButton2.setText("Cats");
jButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e) {
Cats();
}
});
JButton1 jButton2 = new JButton();
jButton1.setBackground(Color.green);
jButton1.setBounds(new Rectangle(100, 120, 85, 32));
jButton1.setFont(new java.awt.Font("Dialog", 1, 14));
jButton1.setText("Dogs");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e) {
Dogs();
}
});
an
"Daniel " <dan...@gmail.com> wrote in message
news:477bab15$1...@newsgroups.borland.com...