aspose file tools
The moose likes Swing / AWT / SWT and the fly likes Listener, Component, Interface Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Java » Swing / AWT / SWT
Reply Bookmark "Listener, Component, Interface" Watch "Listener, Component, Interface" New topic
Author

Listener, Component, Interface

Mike Cole
Ranch Hand

Joined: Sep 25, 2006
Posts: 38
Hi all,

first question is it acceptable to have more than one mouseListener?

2nd.:

Iam trying to prog. a simple game. In the game there are items.(a abstract class called Item). Item is really just the idea of an item, from it i subclass all the real items. -> spoon, screwdriver, flask and so on.
Now i want to make them "selectable", that means, if i move my mouse over an item it should change the graphics(like a button). The graphical representation of such an item is stored in a Class called Sprite. Which itself contains the images and some extra data. Now i found out that there is a class called Component and some interfaces called Accesible*.
My first idea was to subclass my Item class from Component and then add a mouse-listener to it, that way i thought i could find out when an object should be selected. The problem now is... i allready have a mouse-listener which does check other things...and/but only this one works.
So for my 2nd Question... is it a good idea to make my Item a subclass of Component? Or should i write something completly new? In a Component there are so many functions, i dont belive that i ever gonna need half of them.
Do i need any "accesible"-interfaces to reach my goal?(Iam confused by the amount of classes and interfaces java offers). Should i use JComponent or normal Component? Does that idea work? I wish to keep the Item class and Sprite class strictly seperated. (btw. Sprite contains BufferedImage which is drawn onto a Canvas, i hope that doesen�t destroy the idea of components)

Thank you very, very much!
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

I think this topic would do better in the Swing forum. I'll move this there for you.


"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
> i allready have a mouse-listener which does check other things...and/but
> only this one works.

you can add two, and they'll both work



might be better if you can post a sample program (like the above),
that demonstrates the problem you have.


this article might give you some insight into Component vs JComponent
http://java.sun.com/products/jfc/tsc/articles/mixing/

and would specifically apply if you use swing components, and 'Canvas' here
> Sprite contains BufferedImage which is drawn onto a Canvas
is a java.awt.Canvas

if so, you can generally use a JPanel and it's paintComponent(), to
simulate a Canvas
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: Listener, Component, Interface
 
Similar Threads
EventHandling problem.
Java: Arrays of class objects?
Listener, Component, Interface
Popup menu not responding with mouse event
sprite controll help