# Thread: (noob question :0) Making point relative to applet location

1. Senior Member
Join Date
Jul 2010
Posts
125
Rep Power
0

## (noob question :0) Making point relative to applet location

Sorry for asking such a basic question,but:
I have about 90 points that i made in File A (java.awt.Point). They are all relative to 0,0 on the screen, and i unfortunately realized that right when I just got about done with this program. Suppose I need them to be all relative to the applets position on the GUI, but I dont want to have to go back and re-formulate my points. Example:

Applet location (relative to 0,0 on the screen) : 200,200.
Point p location : 144,141.

I need to make that point relative to 200,200. What should I do? Thanks!

2. Um wouldn't adding 200 to all point's x & y's coordinate do the trick?

3. Senior Member
Join Date
Jul 2010
Posts
125
Rep Power
0
This was the obvious solution, but it would take way too long to add this to 90 points. How else?

4. take way too long to add this to 90 points
How long is that? You wouldn't be able to see a tic on the clock for the time to update 90 points.

5. Originally Posted by crikey
Sorry for asking such a basic question,but:
I have about 90 points that i made in File A (java.awt.Point). They are all relative to 0,0 on the screen, and i unfortunately realized that right when I just got about done with this program. Suppose I need them to be all relative to the applets position on the GUI, but I dont want to have to go back and re-formulate my points.
Every JComponent (also in a (J)Applet) has its own coordinate system with its own (0, 0) in its top left corner. If you draw a point (x, y) it will be drawn relative to that position, not relative to the top left corner of the screen.

kind regards,

Jos

6. Senior Member
Join Date
Jul 2010
Posts
125
Rep Power
0
And how do you make it relative to that position? Do you simply click on the applet to activate the coordinate system?

7. Originally Posted by crikey
And how do you make it relative to that position? Do you simply click on the applet to activate the coordinate system?
You don't have to do anything; e.g. if you draw a point at (100, 100) it will be drawn 100 pixels to the right and 100 pixels from the top in the JComponent that does the drawing.

kind regards,

Jos

ps. You could have read this all in the Swing tutorials ...

8. Senior Member
Join Date
Jul 2010
Posts
125
Rep Power
0
Ah okay, thanks. To tell you the truth, I learn by example, and not so much reading. This makes me want to read more next time. Thanks,
Crikey

9. Originally Posted by crikey
Ah okay, thanks. To tell you the truth, I learn by example, and not so much reading. This makes me want to read more next time. Thanks
You're welcome of course; learning by example should be a supplementary activity; you get the fundamental knowledge from the (electronic) books. e.g. this forum is not a tutor although your previous knowledge may be confirmed or denied in these threads.

kind regards,

Jos

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•