Very briefly, in the example a red square is painted on to a JPanel, and moves to a new location specified by either a mouse click or a mouse drag.
I successfully extended the example by having the square move only if the mouse is within its bounds and then dragged. In the original example, the drag start-point did not matter (the square would just move to the drag end-point).
Then thinking about further refining it, I decided on the following mini-specification:
TheRectangle class would define a rectangle and each rectangle object should:
* know its original location and dimensions.
* know its colour
* know if the mouse has been pressed or clicked upon itself * Be able to compute its new location
* Have the responsibility of drawing itself.
ThePanel class would define a panel which:
* would listen for mouse events (in the final implementation just for mousePressed() and mouseReleased() )
* would paint the rectangle onto its surface
* repaint the background of the area vacated when the rectangle moved to a new location.
Now here is the problem:
During de-bugging, I discovered the MouseEvent object is not being passed to the rectangle object.
If it had been, lines 134-138 would have reported the location of the mouse released event?
Am I doing anything wrong? As always, any help will be most welcome.
I'm really sorry for making this post so long, especially as your'e doing this for free, but thankyou again.