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

Reply
 
Thread Tools Search this Thread
  #1  
Old 18-11-2009
Member
 
Join Date: Nov 2009
Posts: 343
Access ActionListener in java

Hi
I have a problem in my code. I have posted it below. In the code I have two classes.
Code:
class 1:
..
..
..
private class Listener implements ActionListener
    {   public void actionPerformed(ActionEvent e)
            {type = e.getActionCommand();}}
..
..
class 2:
..
..
..
private class AddListener implements ActionListener
{   public void actionPerformed(ActionEvent e)
        {  Video video = new Video(?);    }}
..
..
I don't know how to refer to the ActionListener class of class 1 from the ActionListener class of class 2. Please help me.
Reply With Quote
  #2  
Old 18-11-2009
Member
 
Join Date: Oct 2005
Posts: 2,389
Re: Access ActionListener in java

Hi,
I think you have declared the video inside the method, so it will be visible inside that method only. If it is not inside class2 method you can not access it. Please check your program again. Try it you self, if it is not possible we will help you. Next time post your updated code so that we can review it.
Reply With Quote
  #3  
Old 18-11-2009
Member
 
Join Date: Nov 2009
Posts: 343
Re: Access ActionListener in java

Hi
Thanks for the reply. The other way I was thinking to get rid of the Action Listener in class1. By make that change I have to store the button that was clicked in a method and access that method from Action Listener in the class2. This is just my thinking, I do not know if this will work. Any suggestions on this, please advice.
Reply With Quote
  #4  
Old 18-11-2009
Member
 
Join Date: Feb 2008
Posts: 1,848
Re: Access ActionListener in java

Hi
I think your code should be something like this, see the posted code below
Code:
class 1:
private String type = "";
..
..
..
private class Listener implements ActionListener
    {   public void actionPerformed(ActionEvent e)
            {type = e.getActionCommand();}}

public String getType() {
  return type;
}
..
..
Code:
class 2:
private Class1 class1Reference;
public void setClass1(Class1 class1Reference) {
  this.class1Reference = class1Reference;
}
..
..
..
private class AddListener implements ActionListener
{   
  public void actionPerformed(ActionEvent e) {  
    String type = class1Reference.getType();
    Video video = new Video(type);    
  }
}
..
..
If any more queries do post back. And even if solved post, what did you do to solve it.
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Access ActionListener in java"
Thread Thread Starter Forum Replies Last Post
Pass JFrame to actionlistener Freeza 2 Software Development 5 23-08-2010 06:30 PM
Where to use actionlistener ? Anthony12 Software Development 7 09-08-2010 10:20 AM
Add actionlistener to JButton KAMANA Software Development 6 03-08-2010 10:54 AM
File access with Java Alejandro Tips & Tweaks 2 21-07-2010 04:51 AM
Query regarding use of ActionListener in java beelow Software Development 3 16-11-2009 10:56 AM


All times are GMT +5.5. The time now is 09:00 PM.