SWT/Jface ProgressBar-进度条(带来回移动效果的进度条)

销毁的逻辑没有怎么实现-自己捕获异常做相关处理就OK了

 

/**
 * @Title: Test.java
 * @Description: TODO
 * @author zouxs
 * @date 2012-9-25
 */
public class ProgressBarTest {
 public void show_ProgressBar(Composite parent) {

  ProgressBar hBar1 = new ProgressBar(parent, SWT.HORIZONTAL
    | SWT.INDETERMINATE);
  hBar1.setMinimum(0);
  hBar1.setMaximum(100);
  (new IncresingOperator(hBar1)).start();

 }

 class IncresingOperator extends Thread {
  private ProgressBar bar;

  IncresingOperator(ProgressBar bar) {
   this.bar = bar;
  }

  public void run() {
   Display.getDefault().asyncExec(new Runnable() {
    public void run() {
     if (bar.isDisposed())
      return;

     for (int i = 0; i < bar.getMaximum(); i++) {
      System.out.println(">>>>>>>>>>>>>>"+i);
      try {
       Thread.sleep(200);
      } catch (InterruptedException e) {
       e.printStackTrace();
      }
      if(i==29){
       bar.dispose();
      }
      bar.setSelection(bar.getSelection() + 1);
     }
    }
   });
  }
 }

 public static void main(String[] args) {
  Display display = new Display();
  Shell shell = new Shell(display);
  shell.setText("ProgressBar Test:");
  shell.setLayout(new FillLayout(SWT.VERTICAL));

  (new ProgressBarTest()).show_ProgressBar(shell);

  shell.pack();
  shell.open();
  while (!shell.isDisposed()) {
   if (!display.readAndDispatch())
    display.sleep();
  }
  display.dispose();

 }
}

你可能感兴趣的:(SWT/Jface)