• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Hi there I've been stuck for three days now

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The idea of this code is the following: when user clicks on Move Tables button ActionListener should be removed and MouseMotionListener
should be added , when the user clicks back on the Move Tables button it should add ActionListener back and remove MouseMotionListener.
I tried removeMouseMotionListener, but it does not work. I checked that the Move Tables button was working properly but still does not work.
Please tell me what Iam missing or what needs tro be done to remove MouseMotionListener

public void addMouseDragHandlerListener(boolean on)
{
if(on)
{
for(int dm = 0;dm<buttonList.size();dm++)
{
buttonList.get(dm).setCursor(Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR));
buttonList.get(dm).addMouseMotionListener(new DragHandler());
}
}
else if(on==false)
{
for(int dm = 0;dm<buttonList.size();dm++)
{
buttonList.get(dm).setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
buttonList.get(dm).removeMouseMotionListener(new DragHandler());
}

}
}
 
Rancher
Posts: 3324
32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What are we supposed to do with all that code? Its not executable and not fomatted for reading.

Use Code Tags

You can edit your original posting to fix it up (and don't forget to fix the indenting).
 
Ranch Hand
Posts: 686
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Jonathan Johansen wrote:
...
Please tell me what Iam missing or what needs tro be done to remove MouseMotionListener
...



I had a similar problem once. As I recall, in the confusion I had managed to register a listener twice but only removed it once. So it was still generating an event. or something like that.
 
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Consider these lines of code:

ArrayList<String> list = new ArrayList<String>();
list.add("asdf");
list.remove("asdf");
System.out.println(list.size());

As we would expect, the last line outputs "0". Now, look at this code:

ArrayList<Object> list = new ArrayList<Object>();
list.add(new Object());
list.remove(new Object());
System.out.println(list.size());

Here the last line outputs "1". The first object we added is still in the list. Why does that happen?
Well, to answer that, I will first explain why the first lines of code do work. In the second we implicitly create a new string "asdf" and in the third line we create another string "asdf". So we have two different strings with the same character sequences. So how does ArrayList find the correct string to remove? It calls equals(stringToRemove) on all its objects, until it finds an object for which it evaluates to true, and removes it.
Now it is clear why the second example doesn't work as intended - The Object class's equals method simply compares the references of the objects, i.e. it returns the value of this==otherObject.

May this issue apply to your case? Maybe you should override the equals-method in DragHandler to simply return true unconditionally.
 
Bartender
Posts: 2911
150
Google Web Toolkit Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
@ Bernhard Haeussermann and Jonathan Johansen
Welcome to code ranch

@ Jonathan Johansen
1. Your post title is not describing your problem at all
2. use code tags
3. use indentations

Bernhard Haeussermann's answer is correct and it applies to your case.
if you dont have the reference of the object you want to remove, then how do you expect to remove it ?
reply
    Bookmark Topic Watch Topic
  • New Topic