This week's book giveaway is in the Agile and Other Processes forum.
We're giving away four copies of Real-World Software Development: A Project-Driven Guide to Fundamentals in Java and have Dr. Raoul-Gabriel Urma & Richard Warburton on-line!
See this thread for details.
Win a copy of Real-World Software Development: A Project-Driven Guide to Fundamentals in Java this week in the Agile and Other Processes forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Liutauras Vilda
  • Knute Snortum
  • Bear Bibeault
Sheriffs:
  • Devaka Cooray
  • Jeanne Boyarsky
  • Junilu Lacar
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • salvin francis
Bartenders:
  • Tim Holloway
  • Piet Souris
  • Frits Walraven

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

 
Ranch Hand
Posts: 75
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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):








 
Ranch Hand
Posts: 121
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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 am not a spy. Definitely. Definitely not a spy. Not me. No way. But this tiny ad ...
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!