我的例子有问题,代码如下:
public class ProgressBarDemo extends JFrame {
protected int m_min=0;
protected int m_max=100;
protected int m_counter=0;
protected JProgressBar jpb;
public ProgressBarDemo(JButton button) {
jpb=new JProgressBar();
jpb.setMinimum(m_min);
jpb.setMaximum(m_max);
jpb.setStringPainted(true);
button.addActionListener(new ActionListener(){
public void actionPerfromed(ActionEvent e){
new UpdateThread().start();
}
});
//getContentPane().add(jpb,BorderLayout.CENTER);
//getContentPane().add(button,BorderLayout.WEST);
setSize(300,70);
setVisible(true);
}
class UpdateThread extends Thread
{
Runnable runme;
public UpdateThread(){
runme=new Runnable(){
public void run(){
jpb.setValue(m_counter);
}
};
}
public void run()
{
m_counter=m_min;
while(m_counter<=m_max){
SwingUtilities.invokeLater(runme);
m_counter++;
try{
Thread.sleep(500);
}
catch (Exception ex){}
}//end while
}//end run}//end class
public class ProgressBarDemo extends JFrame {
protected int m_min=0;
protected int m_max=100;
protected int m_counter=0;
protected JProgressBar jpb;
public ProgressBarDemo(JButton button) {
jpb=new JProgressBar();
jpb.setMinimum(m_min);
jpb.setMaximum(m_max);
jpb.setStringPainted(true);
button.addActionListener(new ActionListener(){
public void actionPerfromed(ActionEvent e){
new UpdateThread().start();
}
});
//getContentPane().add(jpb,BorderLayout.CENTER);
//getContentPane().add(button,BorderLayout.WEST);
setSize(300,70);
setVisible(true);
}
class UpdateThread extends Thread
{
Runnable runme;
public UpdateThread(){
runme=new Runnable(){
public void run(){
jpb.setValue(m_counter);
}
};
}
public void run()
{
m_counter=m_min;
while(m_counter<=m_max){
SwingUtilities.invokeLater(runme);
m_counter++;
try{
Thread.sleep(500);
}
catch (Exception ex){}
}//end while
}//end run}//end class
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货