public class MoveFrame extends JFrame implements Runnable{ int posX,posY; int n=0;; long sleepTime=500; Thread t; public MoveFrame() { super("threadMove..."); this.setSize(300,300); this.setVisible(true); posX=Toolkit.getDefaultToolkit().getScreenSize().width/2; posY=Toolkit.getDefaultToolkit().getScreenSize().height; this.setLocation(posX,posY); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); t=new Thread(this); t.start();
} public void run() { while(n<this.getHeight()) { posY-=100; this.setLocation(posX,posY); try{ Thread.sleep(sleepTime); } catch(InterruptedException ie) {} n+=100; } } public static void main(String args[]) { new MoveFrame(); } }
int posX,posY;
int n=0;;
long sleepTime=500;
Thread t;
public MoveFrame()
{
super("threadMove...");
this.setSize(300,300);
this.setVisible(true);
posX=Toolkit.getDefaultToolkit().getScreenSize().width/2;
posY=Toolkit.getDefaultToolkit().getScreenSize().height;
this.setLocation(posX,posY);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
t=new Thread(this);
t.start();
}
public void run()
{
while(n<this.getHeight())
{
posY-=100;
this.setLocation(posX,posY);
try{
Thread.sleep(sleepTime);
}
catch(InterruptedException ie)
{}
n+=100;
}
}
public static void main(String args[])
{
new MoveFrame();
}
}