dein Code ist doch unvollständig, enthält kein JFrame zum Testen und vor allem keinen einzigen definierten Button,
von mehreren ganz zu schweigen
hier ein Testprogramm, mühsam selber erstellt (du hast es dir eingespart) mit einem Button,
eine Animation dafür ist definiert, eine Animation erscheint, keine Überraschung..
[code=Java]
public class TestGUI
extends JFrame
{
public TestGUI()
{
Test2 t = new Test2();
t.buttonAnimation(new JButton("hallo"), 30, 30);
add(t);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(400, 400);
setVisible(true);
}
public static void main(String[] args)
{
new TestGUI();
}
}
class Test2
extends JPanel
{
private ButtonThread thread;
private int i = 0;
private class ButtonThread
extends Thread
{
private int x;
private int y;
private JButton button;
public ButtonThread(JButton button, int x, int y, String name)
{
this.button = button;
button.setSize(100, 50);
add(button);
this.x = x;
this.y = y;
setName(name);
}
public void run()
{
boolean status = false;
int yjetzt = button.getLocation().y;
int xjetzt = button.getLocation().x;
while (!status)
{
try
{
sleep(500);
System.out.println("" + button.getLocation().x + " " + button.getLocation().y);
button.setLocation(xjetzt, yjetzt);
if (xjetzt <= x)
{
xjetzt += 10;
}
else
{
if (yjetzt <= y)
{
yjetzt += 10;
}
else
{
status = true;
}
}
}
catch (InterruptedException e)
{
}
}
}
}
public Test2()
{
setLayout(null);
}
public void buttonAnimation(JButton button, int x, int y)
{
thread = new ButtonThread(button, x, y, "" + i);
System.out.println("" + Thread.currentThread());
thread.start();
}
public void paintComponent(Graphics g)
{
g.setColor(Color.white);
g.fillRect(0, 0, this.getWidth(), this.getHeight());
}
}
[/code]