import javax.swing.*;
import java.awt.*;
public class GamePanel extends JFrame implements Runnable{ int sleepTime=1000; int x=0; private static int y=0; Thread move = new Thread(this); myPanel a=new myPanel(); public GamePanel(){ super("移动球"); setSize(500,400); setVisible(true); move.start(); } public void paint(Graphics g) { super.paint(g); g.setColor(Color.RED); g.fillOval(x,x,50,50); } public void run(){ while(true){ if(x<=350){ x += 50; }else{ y += 10; x = y; } repaint(); try{ move.sleep(sleepTime); }catch(InterruptedException e){ } } } public static void main(String args[]){ GamePanel circleFrame = new GamePanel(); circleFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); }}