Results 1 to 6 of 6
- 11-16-2009, 12:50 AM #1
Member
- Join Date
- Nov 2009
- Posts
- 3
- Rep Power
- 0
Hashtable implements ActionListener ?
Hello =)
First sorry for my bad English, I am French and hope to be understandable !
I'm fighting with hashtables, being quite a noobie with them, and I need some help.
Let's see a simplified version of my code :
So, Myhashtable listens to an other object. Initially, foo=3. When an action is fired, Myhashtable sets foo to 2. But when I check afterwards the value of foo, it equals 3, and not 2 !Java Code:public class MyHashtable extends Hashtable implements MyListener { private int foo; public MyHashtable() { this.foo=3; } public void showFoo() { System.out.println("this.foo"); // Prints 3 before action //and strangely prints 3 AFTER action ! } public void MyAction(ActionEvent e) { this.foo=2; showFoo(); // Prints 2 correctly ?? } }
This is driving me crazy, and I am quite sure it is because of my lack of knowledge about hashtables. Sorry if it looks dumb, could anyone help me ?
Thank you :)
-
Why are you extending HashTable here rather than just using it (or even better, use a HashMap)? And what is listening to it?
My guess is that you have more than one of these objects floating around, and the one that changes is not the one that you're testing. But without more information, code and explanation, it's very hard for me to do more than just guess.
Much luck.Last edited by Fubarable; 11-16-2009 at 01:33 AM.
- 11-16-2009, 01:38 PM #3
Member
- Join Date
- Nov 2009
- Posts
- 3
- Rep Power
- 0
Hi, thanks for answering me !
I am extending Hashtable because I need all its features, plus other ones I am implementing. I can't use Hashmap because it is not synchronized, and I am using threads (not sure what it means, but my teacher told us it is better, I'll have to read the Javadoc).
I am sure that I am using only one instance of MyHashtable. Could it be cloned in any way while using the listener ?
I am not on my comptuer so I can't show you any code, but if needed I'll show you a practical example this evening ;)
-
Yeah, I think that we'll need to see more code to get a handle on what's going wrong.
- 11-16-2009, 07:47 PM #5
Member
- Join Date
- Nov 2009
- Posts
- 3
- Rep Power
- 0
Okay, I am really dumb in the end...
While I was building an example for you to show the problem, I noticed that it was my EventListenerList handeling the ActionListener which was wrong : the action was actually performed on a clone of Myhashtable, therefore the non modification.
So your first hunch was right, I didn't work on my original object !
Sorry for my incompetence, now the first thing I'll do when having such a problem is to verify that I am in fact working on the object I assume working on !
Thank you, your first idea was right ;)
-
Similar Threads
-
seeking help for HttpServlet implements CometProcessor
By caho in forum Java ServletReplies: 4Last Post: 11-04-2009, 01:02 PM -
Adding 2 Implements to the class
By jboy in forum New To JavaReplies: 2Last Post: 10-23-2009, 05:19 AM -
HashSet and AbstractSet both Implements Set
By rkjsohi2 in forum New To JavaReplies: 1Last Post: 08-07-2008, 11:04 AM -
How to implements cryptation in a java
By paul in forum Advanced JavaReplies: 1Last Post: 08-07-2007, 05:06 AM -
Implements MyClass extends JFrame
By coco in forum AWT / SwingReplies: 1Last Post: 08-06-2007, 03:43 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks