Results 1 to 4 of 4

Thread: Using Time

  1. #1
    ellias2007 is offline Member
    Join Date
    Feb 2010
    Rep Power

    Default Using Time

    Hi All,

    My Question concerns : "Doing things continuously over time", here is the problem details : (Java and NOT JavaScript)

    Suppose that we need to change the position of a Swing item (JCheckBox for example) from the position : (0,0,70,25) to (100,0,70,25).

    Usually i do :

    Java Code:
    ... And the Box then is moved to the new position IN ZERO SECONDS.

    ... But, what if we need it to go to the new position continuously TAKING 1 SECONDE or more ??!

    (i.e. we need it to move continuously starting from (0,0,70,25) and arriving to (100,0,70,25) in a trip taking 1 second or more)

    Same Question for many other Actions like Changing a Panel Size, Changing a Label Color and so ...

    i have a general idea that we have to use something like Threads or others may be !? but i need a very simple example showing how to do that in a very simple and quick code...

    Many thanks for any help.

    Last edited by ellias2007; 09-04-2010 at 02:43 PM.

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Blog Entries
    Rep Power


    You would use a Swing Timer that moves the component a small bit with each iteration (calling revalidate/repaint after each move) and then which has been set to stop once the component is where you want it. This is no different from other simple Swing animations.

  3. #3
    ellias2007 is offline Member
    Join Date
    Feb 2010
    Rep Power


    Many thanks ... Do u have a simple code please ?!

  4. #4
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Eastern Florida
    Rep Power


    There are lots of pieces of sample/simple code on this forum. Use Search here for "Timer"

    Cross posted at

Similar Threads

  1. Replies: 3
    Last Post: 08-23-2011, 12:46 PM
  2. calculate time diff for particular time period
    By baktha.thalapathy in forum New To Java
    Replies: 2
    Last Post: 05-24-2010, 04:10 PM
  3. Class Time - represents time of day
    By verbazon in forum New To Java
    Replies: 1
    Last Post: 04-13-2009, 01:06 AM
  4. Time
    By Fireking in forum New To Java
    Replies: 3
    Last Post: 09-07-2008, 01:30 AM
  5. Replies: 21
    Last Post: 08-01-2008, 11:13 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