📄 10+
字号:
import javax.swing.*;
import java.awt.*;
import javax.swing.border.*;
class BarWin extends Jframe implements Runnable
{
JprogressBar pbar1,pbar2;
Thread thread1,thread2;
JtextField text1,text2;
BarWin()
{
pbar1=new JprogressBar(0,100);
pbar2=new JprogressBar(0,100);
pbar1.setStringPainted(true);
pbar2.setStringPainted(true);
text1=new JtextField(10);
text2=new JtextField(10);
thread1=new Thread(this);
thread2=new Thread(this);
Box boxV1=Box.createVerticalBox();
boxV1.add(pbar1);
boxV1.add(pbar2);
Box boxV2=Box.createVerticalBox();
boxV2.add(text1);
boxV2.add(text2);
Box baseBox=Box.createHorizontalBox();
baseBox.add(boxV1);
baseBox.add(boxV2);
Container con=getContentPane();
con.setLayout(new FlowLayout());
con.add(baseBox);
setDefaultCloseOperation(Jframe.EXIT_ON_CLOSE);
setBounds(10,10,300,300);
setVisible(true);
validate();
}
public void run()
{
if(Thread.currentThread()==thread1)
{
for(int i=1;i<=100;i++)
{
text1.setText(“第”+i+”项=”+f(i));
pbar1.setValue(i);
try{
Thread.sleep(500);
}
catch(InterruptedException e)
{
}
}
}
if(Thread.currentThread()==thread2)
{
long a1=1,a2=1,a=a1;
int i=1;
while(i<=100)
{
if(i>=3)
{
a=a1+a2;
a1=a2;
a2=a;
}
text2.setText(“第”+i+”项=”+a);
pbar2.setValue(i);
i++;
try{
Thread.sleep(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;
}
}
public class Example
{
public static void main(String args[])
{
BarWin win=new BarWin();
win.thread1.start();
win.thread2.start();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -