import java.awt.Color;
import java.awt.Graphics;
import javax.swing.JFrame;
public class TestThread extends JFrame implements Runnable {
int x=50,y=50;
public TestThread(){
setLocation(200, 200);
setSize(400,300);
setResizable(false);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
}
public static void main(String[] args) {
Thread t = new Thread(new TestThread());
t.start();
}
public void paint(Graphics g) {
super.paint(g);
g.drawString("小马哥来了",x,y);
}
public void run() {
while(true){
try {
Thread.sleep(1000);
x=x+5;//控制速度
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
repaint();
}
}
}
//你看看行吗呢不行告诉我
温馨提示:答案为网友推荐,仅供参考