Results 1 to 9 of 9
  1. #1
    crikey is offline Senior Member
    Join Date
    Jul 2010
    Posts
    125
    Rep Power
    0

    Default (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. #2
    Lil_Aziz1's Avatar
    Lil_Aziz1 is offline Senior Member
    Join Date
    Dec 2009
    Location
    United States
    Posts
    343
    Rep Power
    5

    Default

    Um wouldn't adding 200 to all point's x & y's coordinate do the trick?
    "Experience is what you get when you don't get what you want" (Dan Stanford)
    "Rise and rise again until lambs become lions" (Robin Hood)

  3. #3
    crikey is offline Senior Member
    Join Date
    Jul 2010
    Posts
    125
    Rep Power
    0

    Default

    Thanks mate for your reply-
    This was the obvious solution, but it would take way too long to add this to 90 points. How else?

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,619
    Rep Power
    23

    Default

    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. #5
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,023
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by crikey View Post
    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. #6
    crikey is offline Senior Member
    Join Date
    Jul 2010
    Posts
    125
    Rep Power
    0

    Default

    And how do you make it relative to that position? Do you simply click on the applet to activate the coordinate system?

  7. #7
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,023
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by crikey View Post
    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. #8
    crikey is offline Senior Member
    Join Date
    Jul 2010
    Posts
    125
    Rep Power
    0

    Default

    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. #9
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,023
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by crikey View Post
    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

Similar Threads

  1. Reallyy noob question
    By x2robbie2x in forum New To Java
    Replies: 3
    Last Post: 02-18-2010, 04:58 AM
  2. Noob button question.
    By dudejonne in forum Java Applets
    Replies: 4
    Last Post: 10-20-2009, 10:51 PM
  3. Question - I'm a noob!
    By Insaeno in forum New To Java
    Replies: 5
    Last Post: 08-04-2008, 03:20 AM
  4. Applet Image location
    By MarkWilson in forum NetBeans
    Replies: 3
    Last Post: 06-30-2008, 07:37 AM
  5. Noob question- easy
    By mattonitto in forum New To Java
    Replies: 7
    Last Post: 06-13-2008, 12:26 AM

Posting Permissions

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