Results 1 to 6 of 6
  1. #1
    Zayaan is offline Member
    Join Date
    Nov 2009
    Posts
    3
    Rep Power
    0

    Question 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 :

    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 ??
       }
    }
    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 !

    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 :)

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    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 02:33 AM.

  3. #3
    Zayaan is offline Member
    Join Date
    Nov 2009
    Posts
    3
    Rep Power
    0

    Arrow

    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 ;)

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

  5. #5
    Zayaan is offline Member
    Join Date
    Nov 2009
    Posts
    3
    Rep Power
    0

    Thumbs up

    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 ;)

  6. #6
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by Zayaan View Post
    Thank you, your first idea was right ;)
    You're welcome. It's better to be lucky than to be smart.

Similar Threads

  1. Replies: 4
    Last Post: 11-04-2009, 02:02 PM
  2. Adding 2 Implements to the class
    By jboy in forum New To Java
    Replies: 2
    Last Post: 10-23-2009, 06:19 AM
  3. HashSet and AbstractSet both Implements Set
    By rkjsohi2 in forum New To Java
    Replies: 1
    Last Post: 08-07-2008, 12:04 PM
  4. How to implements cryptation in a java
    By paul in forum Advanced Java
    Replies: 1
    Last Post: 08-07-2007, 06:06 AM
  5. Implements MyClass extends JFrame
    By coco in forum AWT / Swing
    Replies: 1
    Last Post: 08-06-2007, 04:43 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •