代码有冗余,但是实现了旋转地球的多线程打印
import java.applet.*; import java.awt.*; import java.util.*; public class Eearth extends Applet implements Runnable { Thread clockThread; //for(int r=40;r>0;r=r-10){ double r=Math.PI/8; public void start(){ if(clockThread==null){ clockThread=new Thread(this,"Clock"); clockThread.start(); } } public void run(){ while(clockThread!=null){ repaint(); try{ clockThread.sleep(100); }catch(InterruptedException e){} } } public void paint(Graphics g) { for(double angle=0;angle<2*Math.PI;)//周长为零 周长小于2π { g.drawString("*", (100+(int)(50*Math.sin(r)*Math.sin(angle))),100+(int)(50*Math.cos(angle))); //画图 这里是参数方程 x=a+rcosθ y=b+rsinθ angle+=(Math.PI/20.0);//Math.PI 圆周率 这里是打印多少个* } r=r+Math.PI/8; } public void stop(){ clockThread.stop(); clockThread=null; } }