File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes Problem with MouseListener Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Problem with MouseListener" Watch "Problem with MouseListener" New topic
Author

Problem with MouseListener

Steven Joost
Greenhorn

Joined: Sep 29, 2012
Posts: 28
Hello,
I wrote another MouseListener, and it works, but anytime if I click on the panel, the console Writes 200 times "Hello World" instead of once.
What did I wrong?
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
it'll take us a while to find our crystal ball
Steven Joost
Greenhorn

Joined: Sep 29, 2012
Posts: 28
Michael Dunn wrote:it'll take us a while to find our crystal ball

._. I mean what have I to write, to run the event only once?
Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 4344
    
    8

There's no reason there why it would execute more than once. So the problem is probably to do with where you're adding the MouseListener.

My guess is that instead of adding it once when you set the component up, you're adding it somewhere that keeps being executed. That means that you end up with loads of listeners attached to your component, and each event gets sent to all of them.
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4523
    
    5

Thread moved from Beginning Java.

To get better help sooner, post a SSCCE (Short, Self Contained, Correct (Compilable), Example) that demonstrates the problem.

luck, db
There are no new questions, but there may be new answers.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem with MouseListener
 
Similar Threads
JList:Displaying a set of URL's
mouseListener for graphic objects
Problem with my Breakout clone
How to take the data out from JTable?
jtable and jpopupmenu