Results 1 to 8 of 8
- 12-13-2011, 08:56 AM #1
Member
- 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; }
- 12-13-2011, 09:00 AM #2
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,403
- Blog Entries
- 7
- Rep Power
- 17
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,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
- 12-13-2011, 09:04 AM #3
Member
- 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; )
- 12-13-2011, 09:12 AM #4
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,546
- Rep Power
- 11
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.
- 12-13-2011, 09:17 AM #5
Member
- 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?
- 12-13-2011, 09:30 AM #6
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,546
- Rep Power
- 11
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.
- 12-13-2011, 09:41 AM #7
Member
- 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.
- 12-13-2011, 09:43 AM #8
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,546
- Rep Power
- 11
Similar Threads
-
Picking a Collection and Design for querying 1G Point objects
By ennuages in forum Advanced JavaReplies: 8Last Post: 11-22-2010, 10: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: 09-29-2010, 02:38 PM -
Floating point operations is slower when small values are used?
By Cesaro in forum Advanced JavaReplies: 1Last Post: 07-14-2009, 07:04 PM -
Tracking Values Using Objects
By Npcomplete in forum New To JavaReplies: 2Last Post: 10-20-2008, 08:18 PM -
Floating point values in SWT Spinner
By Java Tip in forum SWTReplies: 0Last Post: 07-07-2008, 04:50 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks