• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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,
 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Have you tried getX() and getY() already?
 
sumukha kris
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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,
 
Bartender
Posts: 4121
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!
 
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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,
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic