aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes A MouseEvent object is not Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "A MouseEvent object is not "passed" to an object of another class." Watch "A MouseEvent object is not "passed" to an object of another class." New topic
Author

A MouseEvent object is not "passed" to an object of another class.

Mohammed Azeem
Greenhorn

Joined: Aug 17, 2012
Posts: 12
Hello All,

I'm extending the example used in The Java Tutorials: Lesson: Performing Custom Painting. http://docs.oracle.com/javase/tutorial/uiswing/painting/index.html I've took it apart and learnt a great deal from it.

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.


TheRectangle Class





ThePanel class:





Display class (contains main method):








Maxim Karvonen
Ranch Hand

Joined: Jun 14, 2013
Posts: 94
    
    9
Mohammed Azeem wrote:If it had been, lines 134-138 would have reported the location of the mouse released event?

Why do you think so? I don't see any place where you call testtheclick method. Is it an actual problem or your have forgot something while creating an example?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: A MouseEvent object is not "passed" to an object of another class.
 
Similar Threads
My scrollbars are not displaying
Dispalying random dates
Messagebox with Mouseevent
mouse event for an array of object
How to drag an image along with mouse?