java中有ClockPane类吗_Java程序设计教程 冶金工业出版社第9章
第9章多線程與Applet
//例程9-1:Pi.java
/*演示采用多線程技術計算圓周率*/
public class Pi{
public static void main(String[] args){
PiCaculator pc = new PiCaculator();
Thread t = new Thread(pc);
t.start();
try{
Thread.sleep (10000); //休眠,等待可能出現的異常情況
t.interrupt ();
}catch(InterruptedException e){
e.printStackTrace();
}
}
}
class PiCaculator implements Runnable{
private double latestPiEstimate;
public void run(){
try{
System.out.print ("Math.PI = "+ Math.PI + "\t" );
calPi(0.00001);
System.out.println ("the latest PI = "+http://www.doczj.com/doc/c5af6d3410661ed9ad51f381.htmltestPiEstimate );
}catch(InterruptedException e){
System.out.println("The caculator is Interrupted.");
}
}
/**用于計算圓周率的方法,accuracy為計算精度*/
private void calPi(double accuracy) throws InterruptedException
{
http://www.doczj.com/doc/c5af6d3410661ed9ad51f381.htmltestPiEstimate =0.0;
long iteration = 0;
int sign = -1;
//按給定精度計算圓周率
while(Math.abs (http://www.doczj.com/doc/c5af6d3410661ed9ad51f381.htmltestPiEstimate)>accuracy){
if(Thread.interrupted ())
throw new InterruptedException();
總結
以上是生活随笔為你收集整理的java中有ClockPane类吗_Java程序设计教程 冶金工业出版社第9章的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: java poi 更新excel_在Ja
- 下一篇: java calendar field_