Results 1 to 4 of 4

Thread: Using Time

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

    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:
    MyBox.setBounds(100,0,60,25);
    ... 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.

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

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    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
    Posts
    25
    Rep Power
    0

    Default

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

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,902
    Rep Power
    25

    Default

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

    Cross posted at http://www.javaprogrammingforums.com...sing-time.html

Similar Threads

  1. Replies: 3
    Last Post: 08-23-2011, 01: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, 05:10 PM
  3. Class Time - represents time of day
    By verbazon in forum New To Java
    Replies: 1
    Last Post: 04-13-2009, 02:06 AM
  4. Time
    By Fireking in forum New To Java
    Replies: 3
    Last Post: 09-07-2008, 02:30 AM
  5. Replies: 21
    Last Post: 08-01-2008, 12:13 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
  •