Results 1 to 13 of 13
  1. #1
    theone3nu is offline Member
    Join Date
    Oct 2008
    Posts
    17
    Rep Power
    0

    Default How to use multiple timer classes in swings

    hi... can any one tell how to use two timer classes at a time..... i mean i want to move one image at one speed and the other image at different speed...

  2. #2
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

  3. #3
    theone3nu is offline Member
    Join Date
    Oct 2008
    Posts
    17
    Rep Power
    0

    Default

    ya i can work on multiple threads.... but i want espicially using timer class...can any one help me regarding this...

  4. #4
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

    Default

    Use the Timer class as an inner class, with passing the time period. Check the specific condition, may be complete the move of an image, and stop the time. Something like this.

    Java Code:
        public void moveImages(int time) {
            Timer timer = new Timer(time, new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    // Do the impage moving process
                    // Then stop the timer
                    ((Timer)e.getSource()).stop();
                }
            });
            timer.start();
        }
    Please check the code before use, I've not tested it, simply typed here.

  5. #5
    theone3nu is offline Member
    Join Date
    Oct 2008
    Posts
    17
    Rep Power
    0

    Default

    hey moderator thank u very much for ur reply..... if u dont mind can u give me ur online chatting id so that i can chat with u.... pls give me...

  6. #6
    theone3nu is offline Member
    Join Date
    Oct 2008
    Posts
    17
    Rep Power
    0

    Default

    hey can u be more specific.... actually consider one image is falling at a speed of 2 secs and suppose another image name cursor i want to move that cursor with different speed so that i have to give two time periods...

  7. #7
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

    Default

    Quote Originally Posted by theone3nu View Post
    hey moderator thank u very much for ur reply..... if u dont mind can u give me ur online chatting id so that i can chat with u.... pls give me...
    You can find it from my profile.

  8. #8
    theone3nu is offline Member
    Join Date
    Oct 2008
    Posts
    17
    Rep Power
    0

    Default

    yeah i added u..... waiting for ur response....

  9. #9
    theone3nu is offline Member
    Join Date
    Oct 2008
    Posts
    17
    Rep Power
    0

    Default

    public MoveImage(){
    Timer timer = new Timer(1000,this);
    timer.start();
    }
    public void actionPerformed(ActionEvent e){
    cursor.move();//here i want to give different speed to my cursor image.. how to do that.
    image.move();
    }

    so from the above line i want to give different time to cursor using timer class alone... pls help me regarding this....

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

    Default

    cross-posted in the sun java forums

  11. #11
    theone3nu is offline Member
    Join Date
    Oct 2008
    Posts
    17
    Rep Power
    0

    Default

    hey wats wrong in that.... i want to get the solution thats y i posted in various forums... is it wrong....

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

    Default

    Did you read what I wrote in the cross-post?

    As stated there: This will frustrate anyone who tries to help you only to find out later that the same answer was given hours ago in a cross-posted thread. For this reason, many volunteers here and at the other sites refuse to help repeat offenders.

    It's up to you of course, since no one can stop you from doing it. But ask yourself this: "will I ever want to ask for help in either of these two forums again?" and then act according to what will be most beneficial to you in the future. Good luck.
    Last edited by Fubarable; 12-29-2008 at 05:34 PM.

  13. #13
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

Similar Threads

  1. Drawing charts using swings
    By ravindarjobs in forum New To Java
    Replies: 19
    Last Post: 07-22-2009, 12:03 AM
  2. awt and swings
    By masa in forum AWT / Swing
    Replies: 2
    Last Post: 11-24-2008, 08:09 AM
  3. Replies: 0
    Last Post: 08-19-2008, 05:44 PM
  4. Replies: 0
    Last Post: 04-04-2008, 03:46 PM
  5. java swings
    By emperoraj in forum AWT / Swing
    Replies: 0
    Last Post: 03-26-2008, 12:50 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
  •