progressthread.java~13~
来自「这是各类实用工具的源码100例」· JAVA~13~ 代码 · 共 56 行
JAVA~13~
56 行
package jthreadrace;import javax.swing.*;/** * <p>Title: </p> * <p>Description: </p> * <p>Copyright: Copyright (c) 2002</p> * <p>Company: </p> * @author unascribed * @version 1.0 */public class ProgressThread extends Thread { JProgressBar pbar; static boolean stopped; public ProgressThread(JProgressBar pbar,int priority) { try{ this.pbar=pbar; this.stopped=false; this.setPriority(priority); }catch(Exception err){ err.printStackTrace(); } } void setStop(boolean state){ this.stopped=state; } public void run() { /**@todo Override this java.lang.Thread method*/ int min=0; int max=1000; this.pbar.setMinimum(min); this.pbar.setMaximum(max/10); this.pbar.setValue(min); for(int i=min; i<=max; i++){ if(stopped) break; else{ this.pbar.setValue((int)(i/10)); this.pbar.setString(String.valueOf(i)); try{ Thread.sleep(10); }catch(Exception err){ err.printStackTrace(); } } } }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?