Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Question - Delay

  1. #1
    Junior Member
    Join Date
    Feb 2013
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Question - Delay

    Hello programmers,

    Im trying to make a jLabel ( with an image in it )move in netbeans, but with my current code it moves -5 every ''act?''. I would like to add a delay to it so that it moves -5, then it waits for example 0.5 seconds, and continues. I treid methods like, sleep and wait but i got errors every time. Is there any other way to do it? Or how do i correct use these methods

    My code :


    This is is executed when a certain buttom is preshed : move(-5, 0, 10);

        public void move(int xx, int yy, int ii) {
            for (int i = 0; i < ii; i++) {
                x = mario.getX() + xx;
                y = mario.getY() + yy;
                mario.setBounds(x, y, 91, 117);
            }
        }

    Many thanks in advance!


  2. #2
    Super Moderator curmudgeon's Avatar
    Join Date
    Aug 2012
    Posts
    1,130
    My Mood
    Cynical
    Thanks
    64
    Thanked 140 Times in 135 Posts

    Default Re: Question - Delay

    I don't get a good feel for your code and what you're doing with the small code snipped that you've posted. What is key in my mind is, what are you using to try to do your animation? Myself, I'd use a Swing Timer, and I suggest that you look into doing the same. You can find the tutorial here: The Swing Timer Tutorial.

Similar Threads

  1. 1 packet delay with inputstream
    By tobi06 in forum File I/O & Other I/O Streams
    Replies: 2
    Last Post: October 27th, 2011, 04:53 AM
  2. Delay.
    By Tjstretch in forum Java Theory & Questions
    Replies: 1
    Last Post: October 21st, 2010, 11:18 AM
  3. video game problem - delay in response to arrow key presses
    By gib65 in forum What's Wrong With My Code?
    Replies: 6
    Last Post: October 17th, 2010, 07:39 PM
  4. Delay/Wait/Pause in Java + AirBrushing
    By obliza in forum What's Wrong With My Code?
    Replies: 6
    Last Post: October 27th, 2009, 10:27 AM