本人有以下题:
在JPanel中设置了JprogressBar,然后利用一个线程设置setValue();可是却运行不出,进度条没反应。帮忙看下。
/*此为加有JProgressBar的Jpanel*/
class ProgressPanel extends JPanel{
JProgressBar prog;
public ProgressPanel(){
prog = new JProgressBar(0,1000);
this.add(prog);
}
}
//
class ProgressFrame extends JFrame{
ProgressPanel p;
WindowAdapter listener;
public ProgressFrame(){
p = new ProgressPanel();
this.add(p);
this.setSize(200,300);
listener = new MyListener ();
this.addWindowListener(listener);
this.setVisible(true);
}
public static void main(String [] sargs){
ProgressFrame f = new ProgressFrame();
}
/****内部响应类*****/
class MyListener extends WindowAdapter implements Runnable {
public void WindowOpened(WindowEvent we){
run();
}
/*设置进度条*/
public void run(){
for (int i = 1; i < 6 ; i++)
{
p.prog.setValue(i*200);
try{
Thread.sleep(200);
}
catch(Exception e){}
}
}
}
}
------解决方案--------------------
JavaScript!``