wood burning stoves
The moose likes Threads and Synchronization and the fly likes Threads and listeners Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "Threads and listeners" Watch "Threads and listeners" New topic

Threads and listeners

mogwai mogwai

Joined: May 02, 2006
Posts: 1

I am devloping a board game in java. In order to allow a user to move, i want to detect mouse clicks on the board(graphics2D stuff). I have a method called move that gets the squares a user can move to (Rectangle2D.Float). I add a mouse listener to the board. I then loop and ask the mouse listener for the Point of the last event to check whther one of the allowed rectangles contains it. Unfortunately, it never goes in the mouse listener, it just sits in the loop. I know how to write mouse listeners and I have tested it without the loop.
Is a mouse listener created in a new thread? It seems like the mouse listener's events are never called, and he code in stuck in the main thread.

Plaese help im so confused.

Ernest Friedman-Hill
author and iconoclast

Joined: Jul 08, 2003
Posts: 24199

Hi Mr. Gremlin,

Welcome to JavaRanch!

First, a bit of business: you may not have read our naming policy on the way in. It requires that you use a full, real (sounding) first and last name for your display name. Repeated names of furry 1980's movie characters are not sufficient. You can change your display name here. Thanks for your immediate attention.

Now, as to your question: the mouse listener is going to be invoked on the AWT event thread, while you've presumably got a separate "main" thread that is doing other things. Communication among threads can be tricky when you're just learning. Your explanations are a bit hard to follow, so why don't you illustrate for us with some code?

[Jess in Action][AskingGoodQuestions]
I agree. Here's the link: http://aspose.com/file-tools
subject: Threads and listeners
It's not a secret anymore!