Results 1 to 6 of 6

Thread: moving square

  1. #1
    blindfolded is offline Member
    Join Date
    Jan 2010
    Posts
    4
    Rep Power
    0

    Default moving square

    how can i make a square that moves?in java ? like a car

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

    Default

    Quote Originally Posted by blindfolded View Post
    how can i make a square that moves?in java ? like a car
    First you have to clear the component and draw the square at position (x1, y1); then you wait a bit or do something else and then you repeat the clearing and drawing at position (x2, y2); repeat for position (x3, y3), (x4, y4) etc.

    Note that you have to do the waiting in another thread, i.e. not in Swing's EDT thread. The repainting can simply be accomplished by calling a repaint() on the component that does the drawing of the square at a certain position.

    kind regards,

    Jos

  3. #3
    blindfolded is offline Member
    Join Date
    Jan 2010
    Posts
    4
    Rep Power
    0

    Default pls

    where do i will start?

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

    Default

    Quote Originally Posted by blindfolded View Post
    where do i will start?
    By reading the Sun Tutorials?

    kind regards,

    Jos

  5. #5
    blindfolded is offline Member
    Join Date
    Jan 2010
    Posts
    4
    Rep Power
    0

    Default

    i need it like this there will be 2 buttons when i click the run botton the square will move and when i click the stop button it will stop

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

    Default

    Quote Originally Posted by blindfolded View Post
    i need it like this there will be 2 buttons when i click the run botton the square will move and when i click the stop button it will stop
    Do you want fries with that? First try to get a square drawn on a component; then read up on JButtons and Timers; then think a bit and put it all together.

    kind regards,

    Jos

Similar Threads

  1. How can I square(^2) the pic in the grid
    By racewithferrari in forum New To Java
    Replies: 2
    Last Post: 11-03-2009, 05:27 PM
  2. How can I square(^2) the pic in the grid
    By racewithferrari in forum New To Java
    Replies: 1
    Last Post: 11-01-2009, 10:16 PM
  3. Display Square Roots
    By hypes057 in forum New To Java
    Replies: 8
    Last Post: 08-25-2009, 10:34 AM
  4. Simple square root problem!
    By nortski in forum New To Java
    Replies: 7
    Last Post: 04-01-2009, 02:11 PM
  5. 8-Square puzzle loop
    By SapphireSpark in forum New To Java
    Replies: 7
    Last Post: 12-04-2008, 07:21 PM

Posting Permissions

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