Thread View: borland.public.jbuilder.java.language
6 messages
6 total messages
Started by Daniel
Wed, 02 Jan 2008 14:17
Confused btwn actionPerformed and actionAdapter
Author: Daniel
Date: Wed, 02 Jan 2008 14:17
Date: Wed, 02 Jan 2008 14:17
24 lines
1731 bytes
1731 bytes
Dear fellow developers,
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.
Re: Confused btwn actionPerformed and actionAdapter
Author: Daniel
Date: Wed, 02 Jan 2008 14:46
Date: Wed, 02 Jan 2008 14:46
41 lines
2315 bytes
2315 bytes
Hi all,
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
"Daniel " <dantsg@gmail.com> wrote:
>
>Dear fellow developers,
>
>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.
>
>
>
Re: Confused btwn actionPerformed and actionAdapter
Author: Kevin Dean [TeamB]
Date: Wed, 02 Jan 2008 20:00
Date: Wed, 02 Jan 2008 20:00
19 lines
1900 bytes
1900 bytes
Daniel wrote: >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
Re: Confused btwn actionPerformed and actionAdapter
Author: Bruce Houghtron
Date: Sat, 17 May 2008 20:41
Date: Sat, 17 May 2008 20:41
60 lines
2977 bytes
2977 bytes
Keep it simple, go into the code under jbInit() and rewrite it like this;
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 " <dantsg@gmail.com> wrote in message
news:477bab15$1@newsgroups.borland.com...
>
> Dear fellow developers,
>
> 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.
>
>
>
Re: Confused btwn actionPerformed and actionAdapter
Author: Bruce Houghtron
Date: Sat, 17 May 2008 20:59
Date: Sat, 17 May 2008 20:59
63 lines
3065 bytes
3065 bytes
> Keep it simple, go into the code under jbInit() and rewrite it like this;
>
> jButton2 JButton = 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 JButton = 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 " <dantsg@gmail.com> wrote in message
> news:477bab15$1@newsgroups.borland.com...
>>
>> Dear fellow developers,
>>
>> 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.
>>
>>
>>
>
>
Ops--- Confused btwn actionPerformed and actionAdapter
Author: Bruce Houghtron
Date: Sat, 17 May 2008 21:02
Date: Sat, 17 May 2008 21:02
69 lines
3289 bytes
3289 bytes
"Bruce Houghtron" <bhought@globalserve.net> wrote in message
news:482f4730$1@newsgroups.borland.com...
>
>> Keep it simple, go into the code under jbInit() and rewrite it like
>> this;
>>
>> JButton 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();
>> }
>> });
>>
>> JButton jButton1 = 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 " <dantsg@gmail.com> wrote in message
>> news:477bab15$1@newsgroups.borland.com...
>>>
>>> Dear fellow developers,
>>>
>>> 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.
>>>
>>>
>>>
>>
>>
>
>
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads