Results 1 to 8 of 8
 12132011, 09:56 AM #1Member
 Join Date
 Dec 2011
 Posts
 7
 Rep Power
 0
How to find x and y values of Point objects?
Hi, I'm writing a class Rectangle that has private int x, y, width, height, and Point p1. I need to change just the Point's x and y values.
I'm having trouble getting the x and y values of a Point p. I brought in the Point p from main, so I'm getting the error: x has private access in Point.
Is this because I didn't initialize p in the constructor itself?
I would really appreciate any help!
This is my constructor below:
Java Code:public Rectangle(Point p, int width, int height) { this.p1 = p; this.x = p.x; this.y = p.y; this.width = width; this.height = height; }
 12132011, 10:00 AM #2
 Join Date
 Sep 2008
 Location
 Voorschoten, the Netherlands
 Posts
 13,931
 Blog Entries
 7
 Rep Power
 22
Re: How to find x and y values of Point objects?
In my version of the JSE classes the Point class has public members x and y ... are you using your own Point class?
kind regards,
Joscenosillicaphobia: the fear for an empty beer glass
 12132011, 10:04 AM #3Member
 Join Date
 Dec 2011
 Posts
 7
 Rep Power
 0
Re: How to find x and y values of Point objects?
Yes, I am using my own Point class. Even when I import the java.awt package, I still can't do ( this.x = p.x; )
 12132011, 10:12 AM #4Moderator
 Join Date
 Feb 2009
 Location
 New Zealand
 Posts
 4,684
 Rep Power
 13
Re: How to find x and y values of Point objects?
If it's your own Point class, then write a setX() method for it that's public. And use that method to change the value.
 12132011, 10:17 AM #5Member
 Join Date
 Dec 2011
 Posts
 7
 Rep Power
 0
Re: How to find x and y values of Point objects?
Thanks, but how should I call that in my Rectangle constructor?
 12132011, 10:30 AM #6Moderator
 Join Date
 Feb 2009
 Location
 New Zealand
 Posts
 4,684
 Rep Power
 13
Re: How to find x and y values of Point objects?
You would call the setter methods whereever you want to set the values.

You said you wanted to set a point's values. But you also said your rectangle also has x and y values. Are you sure you don't want to get the point's values and assign them to x and y of the rectangle? The process is the same: write getter methods for the point class and use them wherever you like  including in the rectangle constructor if that makes sense.
 12132011, 10:41 AM #7Member
 Join Date
 Dec 2011
 Posts
 7
 Rep Power
 0
Re: How to find x and y values of Point objects?
Thank you so much! I finally got everything after three hours of confusion. Thanks a bunch.
 12132011, 10:43 AM #8Moderator
 Join Date
 Feb 2009
 Location
 New Zealand
 Posts
 4,684
 Rep Power
 13
Similar Threads

Picking a Collection and Design for querying 1G Point objects
By ennuages in forum Advanced JavaReplies: 8Last Post: 11222010, 11:09 AM 
how to use objects and its values to use in other function without using parameters
By sfaiz in forum New To JavaReplies: 3Last Post: 09292010, 02:38 PM 
Floating point operations is slower when small values are used?
By Cesaro in forum Advanced JavaReplies: 1Last Post: 07142009, 07:04 PM 
Tracking Values Using Objects
By Npcomplete in forum New To JavaReplies: 2Last Post: 10202008, 08:18 PM 
Floating point values in SWT Spinner
By Java Tip in forum SWT TipsReplies: 0Last Post: 07072008, 04:50 PM
Bookmarks