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

• 08-25-2010, 04:46 AM
crikey
(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!
• 08-25-2010, 04:56 AM
Lil_Aziz1
Um wouldn't adding 200 to all point's x & y's coordinate do the trick?
• 08-25-2010, 03:08 PM
crikey
This was the obvious solution, but it would take way too long to add this to 90 points. How else?
• 08-25-2010, 03:33 PM
Norm
Quote:

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.
• 08-25-2010, 03:37 PM
JosAH
Quote:

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
• 08-25-2010, 04:07 PM
crikey
And how do you make it relative to that position? Do you simply click on the applet to activate the coordinate system?
• 08-25-2010, 04:09 PM
JosAH
Quote:

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 ...
• 08-25-2010, 04:18 PM
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,
Crikey
• 08-25-2010, 04:22 PM
JosAH
Quote:

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