Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Register Tags Active Topics RSS Search Mark Forums Read

Sponsored Links



Query regarding use of ActionListener in java

Software Development


Reply
 
Thread Tools Search this Thread
  #1  
Old 16-11-2009
Member
 
Join Date: May 2008
Posts: 69
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..

Reply With Quote
  #2  
Old 16-11-2009
Member
 
Join Date: Oct 2005
Posts: 2,388
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.
Reply With Quote
  #3  
Old 16-11-2009
Member
 
Join Date: May 2008
Posts: 2,377
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
Reply With Quote
  #4  
Old 16-11-2009
Member
 
Join Date: Feb 2008
Posts: 1,844
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)
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Query regarding use of ActionListener in java"
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 09:04 AM
Query in java classes Aaliya Seth Software Development 5 26-02-2010 12:34 AM
Query with Date in java Gunner 1 Software Development 5 12-02-2010 02:55 AM
Access ActionListener in java Windowed Software Development 3 18-11-2009 01:57 PM
[JAVA] query results in a combobox and jtextfield Aamin Software Development 5 31-03-2009 02:20 PM


All times are GMT +5.5. The time now is 11:49 AM.