请完成下列Java程序:创建一个进度条,可以控制其开始和暂停。要求进度条与线程关联,由线程控制,点击开始按钮开始进度条的滚动,点击停止按钮,暂停,继续点击开始按钮则继续进行。注意:请勿改动main()主方法和其他已有的语句内容,仅在横线处填入适当的语句。import javax.swing.*;import javax.swing.event.*;import java.awt.*;import java.awt.event.*;public class ex15_2 extends JPanel {ThreadProg thProgress;JProgressBar jPb;//声明一个进程条对象static JFrame. jf;public ex15_2(){setLayout(new BorderLayout());jPb=new JProgressBar();add(jpb,"Center");JPanel btnPanel=new JPanel();JButton btnStart=new JButton("开始");btnPanel.add(btnStart);btnStart.addActionListener(new ActionListener(){public void actionPerformed(ActionEvent ae){__________;}});JButton btnStop=new JButton("停止");btnPanel.add(btnStop);btnStop.addActionListener(new ActionListener(){public void actionPerformed(ActionEvent ae){__________;}});add(btnPanel,BorderLayout.SOUTH);}public void startProgress(){if(thProgress==null||!thProgress.isAlive()){thProgress=new ThreadProg(jpb);thProgress.start();}}public void stopProgress(){thProgress.setStop(true);}pubUc static VOid main(String args[]){jf=new JPrame("ex15_2");ex15_2 obj15_2=new ex15_2();jf.getContentPane().add("Center",obj15_2);jf.setSize(250,80);jf.addWindowListener(new WindowAdapter(){pubhc void windowClosing(WindowEvent we){System.exit(0);}});jf.setVisible(true);}}class ThreadProg extends Thread{private JProgressBar jpb;private boolean bStop=false;private boolean bAlive=false;pubhc ThreadProg(JProgressBar jpb){this.jpb=jpb;}public VOid setStop(boolean b){bStop=b;}public void run(){int min=0;int max=60;jpb.setMinimum(min);jpb.setMaximum(max);jpb.setValue(min);for(int x=min;x<=max;x++){if(bStop){break;}else{jpb.setValue(x);try{Thread.sleep(150);} catch(InterruptedException e){}}}bAlive=false;}}
请完成下列Java程序:创建一个进度条,可以控制其开始和暂停。要求进度条与线程关联,由线程控制,点击开始按钮开始进度条的滚动,点击停止按钮,暂停,继续点击开始按钮则继续进行。
注意:请勿改动main()主方法和其他已有的语句内容,仅在横线处填入适当的语句。
import javax.swing.*;
import javax.swing.event.*;
import java.awt.*;
import java.awt.event.*;
public class ex15_2 extends JPanel {
ThreadProg thProgress;
JProgressBar jPb;//声明一个进程条对象
static JFrame. jf;
public ex15_2(){
setLayout(new BorderLayout());
jPb=new JProgressBar();
add(jpb,"Center");
JPanel btnPanel=new JPanel();
JButton btnStart=new JButton("开始");
btnPanel.add(btnStart);
btnStart.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent ae){
__________;
}
});
JButton btnStop=new JButton("停止");
btnPanel.add(btnStop);
btnStop.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent ae){
__________;
}
});
add(btnPanel,BorderLayout.SOUTH);
}
public void startProgress(){
if(thProgress==null||!thProgress.isAlive()){
thProgress=new ThreadProg(jpb);
thProgress.start();
}
}
public void stopProgress(){
thProgress.setStop(true);
}
pubUc static VOid main(String args[]){
jf=new JPrame("ex15_2");
ex15_2 obj15_2=new ex15_2();
jf.getContentPane().add("Center",obj15_2);
jf.setSize(250,80);
jf.addWindowListener(new WindowAdapter(){
pubhc void windowClosing(WindowEvent we){
System.exit(0);
}
});
jf.setVisible(true);
}
}
class ThreadProg extends Thread{
private JProgressBar jpb;
private boolean bStop=false;
private boolean bAlive=false;
pubhc ThreadProg(JProgressBar jpb){
this.jpb=jpb;
}
public VOid setStop(boolean b){
bStop=b;
}
public void run(){
int min=0;
int max=60;
jpb.setMinimum(min);
jpb.setMaximum(max);
jpb.setValue(min);
for(int x=min;x<=max;x++){
if(bStop){
break;
}else{
jpb.setValue(x);
try{
Thread.sleep(150);
} catch(InterruptedException e){
}
}
}
bAlive=false;
}
}