Jump to content

Animation

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
1 reply to this topic

#1
p4ss

p4ss

    Newbie

  • Members
  • Pip
  • 1 posts
hi guys

public void run() 
{
            int x = 10; int y = 10;
            while (true) 
            {
     label.setText("DATA");           
label.setBounds(x, y, 200, 10);

                if(y == 250 && x != 250) x+=5;
                else if(x == 250){
                    y -= 5;
                    if( y == 10) break;
                }
                else y +=5;
                }
}

Based on the part of my program i want the animation of 'label" to adjust to window screen size..
how can i do that..

Edited by ZekeDragon, 21 March 2010 - 12:26 AM.
Please use [code] tags (the # button) when you post code.


#2
wim DC

wim DC

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 2,084 posts
So instead of moving the JLabel you want to adjust the window size right? (By the way i didn't see the label move untill i added
try {
                sleep(10);
            } catch (InterruptedException e) {
                e.printStackTrace();  
            }
Otherwise the label goes straight to it's final position from the start.

Back to the window screen size issue:
SwingUtilities.getRoot(label).setSize(x,y);
All you need :D

The x,y loop is not infinite, yet the thread will keep running. It's probably better to do while(boolean) and then check inside if x and y is at it's final position, then set the boolean to false.