I am writing a style exercice in preparation of a complex program I wish to write in which I'll be dragging around all sorts of objects
that will react differently depending on the area's they are dragged over and dropped in.
So, first I'm coding a simple Hanoi style game in which the tiles are to be dragged onto the tower areas. The towers are to change color when the
tile is dragged over them, and the tile itself has to change color when it is clicked upon.
Now, I'm a beginner OO programmer. So I'm trying to make each object react to mouse events in its own class. I don't know if this is the
correct way or whether it is possible at all, but it's not working in my code. Could someone have a look at it?
Here is the main class:So basically I'm making a screen with three towers, with five tiles on the first one.
The screen gets drawn at startup and draws the towers. A first mouselistener is added, but as a test all it does is type a message to the console whenever the screen is clicked on. This seems to be working.
Next comes the Tower class:I stripped this class to the bare necessities. It has its own mouselistener, which is supposed to send a message to the console whenever the tower area is clicked upon, but it doesn't work. And I can't figure out why.
Same problem in the Tile class:Same here, the message never gets sent. The local mouselistener doesn't seem to respond.
Any ideas what I'm doing wrong? Thanks a lot in advance.