日期:2014-05-20 浏览次数:20786 次
import java.awt.Color; import java.awt.Graphics; import javax.swing.JFrame; public class cricle extends JFrame { int x=80,y=80; public void launch(){ //setLocation(400, 300); setSize(700,800); setLocationRelativeTo(null); //jframe居中显示 setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setResizable(false); //jframe不可改变大小 setBackground(Color.YELLOW); setVisible(true); Thread t=new Thread(new RunTank()); t.start(); } //画物体 public void paint(Graphics g){ Color c=g.getColor(); g.setColor(Color.red); g.fillOval(x,y, 40, 40); g.setColor(c); y+=50; } //物体运动 class RunTank implements Runnable{ public void run() { while(true) { repaint(); try { Thread.sleep(100); } catch (InterruptedException e) { e.printStackTrace(); } } } } public static void main(String[] args) { cricle tan= new cricle(); tan.launch(); } }