This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
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?
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.
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;
Joined: Nov 02, 2007
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 ?