This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes Problem in finding the bounds of rectangle..... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Problem in finding the bounds of rectangle....." Watch "Problem in finding the bounds of rectangle....." New topic
Author

Problem in finding the bounds of rectangle.....

sumukha kris
Greenhorn

Joined: Nov 02, 2007
Posts: 18
Hello,

How to find the x and y co ordinate of a rectangle in terms of number.
Is there any method .I want it to return the x y co ordinate of that rectangle.
There is getBounds() which returns a rectangle itself but i need in terms of values.
How to do this?

Thanks in advance,
Frank Bacher
Greenhorn

Joined: Oct 25, 2002
Posts: 19
Have you tried getX() and getY() already?
sumukha kris
Greenhorn

Joined: Nov 02, 2007
Posts: 18
Thanks for replying..

I tried but it gives the co ordinate position of the mouse click but i need the co ordinates of the drawn rectangle.....
How to do this....

Thanks in advance,
Nathan Pruett
Bartender

Joined: Oct 18, 2000
Posts: 4121

Rectangle.getX/Y(), not MouseEvent.getX/Y().

"sumukha " -

Welcome to the JavaRanch! We don't have many rules around the ranch, but we do have a policy on displayed names... Please adjust your displayed name to meet the JavaRanch Naming Policy. User names must consist of a first name and a last name.

You can change your user name here.

Thanks! and welcome to the JavaRanch!


-Nate
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
Craig Wood
Ranch Hand

Joined: Jan 14, 2004
Posts: 1535
How to find the x and y co ordinate of a rectangle in terms of number
Look in the Rectangle class api to find what you have to work with.
In the Fields Summary section you have access to the fields "x" and "y".
In the Methods Summary section you have access to the methods
getX, getY, getLocation and getBounds.
For a given
Rectangle rect = someRectangle
the x part of the location (x, y) of "rect" is accessible with:
int x = rect.x;
double x = rect.getX();
int x = rect.getBounds().x;
int x = rect.getLocation().x;
sumukha kris
Greenhorn

Joined: Nov 02, 2007
Posts: 18
Thanks for replying.
I tried all the menioned methods but it s giving "method cannot be resolved for Rubber1.fig" Rubber1 is name of my project.

I need the size of the rectangle in order to pass the width and height of rectangle to the Buffered Image and i need to draw a spiral within this rectangle. It s printing the co ordinate positions at mouse click and release so the click has got (ax,ay) and release has got (bx,by) so i subtracted (bx-ax) (by-ay) to get width and height of rectangle resp. But now the problem is that it s taking the left top corner of panel as (0,0)
but i need to set the topleft corner of rectangle as (0,0) where ever it s drawn within the panel.So how to set the topleft corner of rectangle as (0,0). How to do it ?

regards,
 
GeeCON Prague 2014
 
subject: Problem in finding the bounds of rectangle.....