Thread importThread = new Thread(new Runnable() {
@Override
public void run() {
try {
openImportPath();
} catch (TCException e) {
eprintStackTrace();
}
}
});
importThreadstart();
Thread barThread = new Thread(new Runnable() {
@Override
public void run() {
while(bar<101){
progressbarsetValue(bar);
}
}
});
barThreadstart();
两个线程,一个实现 openImportPath()方法(这是我写的一个导入数据的方法),另一个就是实现进度条了,进度条就是为了显示导入数据的进度。你可以参考。给你给程序你看看吧!一看就会懂得
import javaxswing;
import javaawt;
import javaxswingborder;
public class Example10_17{
public static void main(String args[]){
new BarWin();
}
}
class BarWin extends JFrame implements Runnable{
JProgressBar pbar1,pbar2;
Thread thread1,thread2;
JTextField text1,text2;
int number=50;
BarWin(){
pbar1=new JProgressBar(0,number);
pbar2=new JProgressBar(0,number);
pbar1setStringPainted(true);
pbar2setStringPainted(true);
text1=new JTextField(10);
text2=new JTextField(10);
thread1=new Thread(this);
thread2=new Thread(this);
Box boxV1=BoxcreateVerticalBox();
boxV1add(pbar1);
boxV1add(pbar2);
Box boxV2=BoxcreateVerticalBox();
boxV2add(text1);
boxV2add(text2);
Box baseBox=BoxcreateHorizontalBox();
baseBoxadd(boxV1);
baseBoxadd(boxV2);
setLayout(new FlowLayout());
add(baseBox);
setDefaultCloseOperation(JFrameEXIT_ON_CLOSE);
setBounds(10,10,300,300);
setVisible(true);
thread1start();
thread2start();
}
public void run(){
if(ThreadcurrentThread()==thread1){
for(int i=1;i<=number;i++){
text1setText("第"+i+"项="+f(i));
pbar1setValue(i);
try{ Threadsleep(500);
}
catch(InterruptedException e){}
}
}
if(ThreadcurrentThread()==thread2){
long a1=1,a2=1,a=a1;
int i=1;
while(i<=number){
if(i>=3){
a=a1+a2;
a1=a2;
a2=a;
}
text2setText("第"+i+"项="+a);
pbar2setValue(i);
i++;
try{ Threadsleep(500);
}
catch(InterruptedException e){}
}
}
}
long f(int n){
long c=0;
if(n==1||n==2)
c=1;
else if(n>1)
c=f(n-1)+f(n-2);
return c;
}
}你如果使用Java Media Framework 21(也就是JMF21),其中的Player player;playerstop();方法,就是有暂停功能,
当执行Player player;playerstop();playersetMediaTime(new Time(0));后,音乐就停止了,如果执行Player player;playerstop();,音乐就暂停,直到执行playerstart();,音乐继续
因此,playerstart();有开始播放和暂停后继续播放的功能,playerstop();有暂停和停止(如果playersetMediaTime(new Time(0));)的功能
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)