• Post Reply Bookmark Topic Watch Topic
  • New Topic

Listener, Component, Interface  RSS feed

 
Mike Cole
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think this topic would do better in the Swing forum. I'll move this there for you.
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
> 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
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!