因为你的整个程序只是用了一个线程,单线程的程序只能由一个函数在运行,所以整个界面就会没有反应。解决办法是:在此类中实现多线程接口(Runnable),将文件操作放在一个单独的线程中即可。具体可参考多线程编程。class PrimeRun implements Runnable {
long minPrime;
PrimeRun(long minPrime) {
this.minPrime = minPrime;
}
public void run() {
// compute primes than minPrimelarger
. . .
}
}
The following code would then create a thread and start it running:
PrimeRun p = new PrimeRun(143);
new Thread(p).start();
long minPrime;
PrimeRun(long minPrime) {
this.minPrime = minPrime;
}
public void run() {
// compute primes than minPrimelarger
. . .
}
}
The following code would then create a thread and start it running:
PrimeRun p = new PrimeRun(143);
new Thread(p).start();
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货