Java by API/org.eclipse.swt.custom/BusyIndicator — различия между версиями

Материал из Java эксперт
Перейти к: навигация, поиск
м (1 версия)
 
(нет различий)

Текущая версия на 14:43, 31 мая 2010

BusyIndicator.showWhile(Display com, Runnable run)

import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.BusyIndicator;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
public class MainClass {
  public static void main(String[] a) {
    
    final Display d = new Display();
    final Shell shell = new Shell(d);
    shell.setSize(250, 200);
    
    final String RUN = "Press to Run";
    final String IS_RUNNING = "Running...";    
    
    shell.setLayout(new FillLayout());
    final Button button = new Button(shell, SWT.PUSH);
    button.setText(RUN);
    button.addSelectionListener(new SelectionAdapter() {
      public void widgetSelected(SelectionEvent event) {
        button.setText(IS_RUNNING);
        BusyIndicator.showWhile(button.getDisplay(), new SleepThread(1000));
        button.setText(RUN);
      }
    });
    
    
    
    shell.open();
    while (!shell.isDisposed()) {
      if (!d.readAndDispatch())
        d.sleep();
    }
    d.dispose();
  }
}
class SleepThread extends Thread {
  private long ms;
  public SleepThread(long ms) {
    this.ms = ms;
  }
  public void run() {
    try {
      sleep(ms);
    } catch (InterruptedException e) {}
  }
}