File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes Shapes return 0's as coordinates, width & height Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Shapes return 0 Watch "Shapes return 0 New topic
Author

Shapes return 0's as coordinates, width & height

Veronique Kus
Ranch Hand

Joined: Jun 13, 2010
Posts: 41
Hi,
the code below is supposed to allow me to draw mutliple shapes.
Currently I'm trying to implement selecting shapes by clicking on them (to be able to drag them to a different location).
In the mouseClicked() method, I check whether the user just clicked inside a shape. However, it never returns true.
In the mouseExited() method I print width, height and class name of each of the shapes contained in the shapeList (which contains
all shapes drawn by the user). As it turns out, all shapes return zero values for width, height, central point coordinates etc. and I have no idea why?
My shape class extends the Rectangle2D.Double class so I don't know why methods like getHeight() etc. don't work properly on my shapes... If I override these methods
in my Shape implementation, they return correct values but I want to use the standard implementations contained in the Rectangle2D.Double class.

I would be veeery grateful for help with this!






Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24166
    
  30

Those "standard implementations" operate on the data held inside the Rect2D.Double class. Your subclass defines its own data, and it's only your own data that is initialized in your constructors. Instead, your implementation must use the member variables already defined in the superclass, and your constructors must make sure that data is initialized by calling the proper superclass constructors.


[Jess in Action][AskingGoodQuestions]
Veronique Kus
Ranch Hand

Joined: Jun 13, 2010
Posts: 41
Forgot about an obvious thing, thank you.
 
 
subject: Shapes return 0's as coordinates, width & height
 
Similar Threads
Line delete problem in jpanel on mouse clicked
previously drawn shapes disappear when new one is created
A Paint Application with Combo Boxes and Buttons
Drawing text inside a Graphics2D shape
KeyListener problem