On Sun, 03 May 2009 18:10:17 -0700, sso <strongsilent...@gmail.com> wrote:
I'm new to Java so the answer to my question may be quite simple.
Basically my Main class is a JFrame. The JFrame contains an instance
of the "board" class. The board class contains several tiles
(Graphics). I need to be able to detect MouseListeners to the
tiles. I've done things with MouseListeners (adapters etc) with
standard swing components and not had trouble. Perhaps there is
something I don't know or I'm forgetting some of the basics.
Suggestions?
My first suggestion is to make sure when you post looking for an answer,
that you've included a specific question. :)
Suggestion number two is that you post a concise-but-complete code example
that reliably demonstrates whatever issue you're having.
From your post, it's hard to know what you're having trouble with. If the
code example is everything you've got, then there are several problems:
-- You have two class declarations that promise to implement the
MouseListener interface, but then never actually implement it
-- You never call addMouseListener() on any component, so events for
your (non-existent) MouseListener implementations would never be raised
-- You try to call an add() method on an instance of Container with an
argument of a type that is not compatible with any overload for add()
found in Container
-- You execute AWT/Swing code on a thread that is not the Event
Dispatch Thread
-- You override the paintComponent() method in a class that does not
extend JComponent (or any class implementing paintComponent() for that
matter)
And those are just the obvious ones I found.
Either the code that you posted isn't anywhere close to being useful, or
it isn't anywhere close to being the code you're actually using. In
either case, since you haven't posted a specific question to go along with
the code, it's not even possible to make some guesses as to what problem
you might be having, never mind offer a specific solution to whatever
problem you are actually having.
Try again? :)
Pete
Well, lets go back to the beginning. :)
I'm trying to build a little game. Essentially I need to be able to
detect clicks on the tiles on the board, then I can go from there.
The reason the code looks useless is..... well... because it probably
force it.
be a class that extends a JComponent (panel, label, etc).
MouseEvent occurred on. I'm not sure how to determine which tile the
MouseEvent occurred on.