Results 1 to 4 of 4
Thread: How to access the ActionListener
- 10-15-2009, 12:35 PM #1
Member
- Join Date
- Aug 2009
- Posts
- 56
- Rep Power
- 0
How to access the ActionListener
Hi,
I have two classes and each class has an ActionListener class within it.
My problem is that I don't know how to refer to the ActionListener class of class 1 from the ActionListener class of class 2, so that I can put the "type"Java 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(?); }} .. ..
from the first ActionListener into the "Question mark" in the second ActionListener.
Thanks in advance.
- 10-15-2009, 12:47 PM #2
Senior Member
- Join Date
- Aug 2009
- Posts
- 2,388
- Rep Power
- 6
You can't. The video is declared inside the method so it is only visible inside that method only. You can't even access it from class 2 itself when not inside that method. Relook your design.
- 10-15-2009, 01:37 PM #3
Member
- Join Date
- Aug 2009
- Posts
- 56
- Rep Power
- 0
The only other way that I think of doing this is to get rid of the ActionListener in class 1, and I have to store the Button that was clicked in a method and access that method from the ActionListener in the class 2. But I don't know how to go about finding out which button is clicked without using any listener if we follow what I just described.
Thanks.
-
Java Code:class 1: private String type = ""; .. .. .. private class Listener implements ActionListener { public void actionPerformed(ActionEvent e) {type = e.getActionCommand();}} public String getType() { return type; } .. .. 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); } } .. ..
Similar Threads
-
NullPointerException by ActionListener
By YouGina in forum AWT / SwingReplies: 8Last Post: 07-10-2009, 11:08 AM -
Determining ActionListener
By siamino in forum New To JavaReplies: 12Last Post: 05-25-2009, 11:04 PM -
Java actionlistener help
By justsomeguy in forum AWT / SwingReplies: 1Last Post: 05-27-2008, 05:42 AM -
Demonstrating the ActionListener
By Java Tip in forum java.awtReplies: 0Last Post: 04-23-2008, 08:20 PM -
ActionListener interface
By tsantana in forum New To JavaReplies: 2Last Post: 03-30-2008, 10:24 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks