Win a copy of Fixing your Scrum this week in the Agile 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Rob Spoor
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Junilu Lacar
  • Tim Cooke
Saloon Keepers:
  • Tim Holloway
  • Piet Souris
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Frits Walraven
  • Himai Minh

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

 
Ranch Hand
Posts: 88
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
There is no "i" in denial. Tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic