|
|
![]() |
| Thread Tools | Search this Thread |
#1
| |||
| |||
Query regarding use of ActionListener in java Hi. I am getting confused about the use of ActionListeners in the java program. If I take multiple listeners in one program, is it valid? The I using one listener for each button,only if each button is in it's own inner class. In another program I'm using around 15 or more listeners in it. Is it anything invalid with programmer OR it is ok to use only one ActionListener in the program? Please suggest me.. |
#2
| |||
| |||
Re: Query regarding use of ActionListener in java I'm not confirmed about behavior of java, if you add a single object but multiple times to the same object. But I know this is completely unnecessary. Suppose if you have two different buttons, and if you want your program to listen to both buttons. For this you have to add your main program to the ActionListeners list of each button you have taken. Please make sure that your main program is not duplicating the actionsPerformed by two buttons(which you have defined) listening to each other.I hope this will solve your query.
__________________ Grand Theft Auto 4 PC Video Game |
#3
| |||
| |||
Re: Query regarding use of ActionListener in java Your method look harder to adapt ,should you wish to listen to the same command coming from different places. According to my Java skill ,creating a general listener makes it easier to take advantages of inheritance in java programming. For reference see below example: //Base class public class AppFrm extends JFrame implements ActionListener{ public void actionPerformed(ActionEvent e){ if ( e.getActionCommand().equals("Something") ){ doSomething(); }else if ( e.getActionCommand().equals("Else") ){ doElse(); } } } //Inherited Class public class NextFrame extends AppFrm implements ActionListener{ public void actionPerformed(ActionEvent e){ if ( e.getActionCommand().equals("Something") ){ doSomthingElse(); super.actionPerformed(e); }else{ super.actionPerformed(e); } } }
__________________ The FIFA Manager 2009 PC Game |
#4
| |||
| |||
Re: Query regarding use of ActionListener in java In java ActionListener interface is used to receive events.The ActionListener interface extends EventListerner The class which is interested in processing an action event implements this interface, and the object created with that class is registered with a component, using the component's addActionListener method. actionPerformed method is invoked only when the event occurs. Syntax for this is: 1. actionPerformed(ActionEvent e) 2.public void actionPerformed(ActionEvent e) |
![]() |
|
Tags: actionlistener, actionlistener in java, java, use of actionlistener |
Thread Tools | Search this Thread |
|
![]() | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Looking for Excel Web Query for Java Applet working sample | Omswaroop | MS Office Support | 3 | 17-01-2014 10:04 AM |
Query in java classes | Aaliya Seth | Software Development | 5 | 26-02-2010 01:34 AM |
Query with Date in java | Gunner 1 | Software Development | 5 | 12-02-2010 03:55 AM |
Access ActionListener in java | Windowed | Software Development | 3 | 18-11-2009 02:57 PM |
[JAVA] query results in a combobox and jtextfield | Aamin | Software Development | 5 | 31-03-2009 02:20 PM |