SWT Tips and Samples 基礎編 > BusyIndicator

 

BusyIndicator

BusyIndicatorは処理状況をポインタの形状で示すユーティリティー的なクラスです。何らかの処理が行われているということを明示的にユーザーに知らせたい場合などに利用します。Runnableインターフェースを持つオブジェクトをBusyIndicatorクラスのshowWhileメソッドに渡すと、自動的にrunメソッドが実行されます。runメソッド内の処理が行われている間、ポインタの形状が砂時計アイコンに変わります。

BusyIndicator.showWhile(display, thread);

サンプルプログラムではボタンが押されると、10秒間スリープ状態になりマウスの形状が変わります。

スクリーンショット

ソースコード (BusyIndicatorTest.java)

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.*;
import org.eclipse.swt.widgets.*;

public class BusyIndicatorTest {
        private Thread thread;
        private Display display;
        private Button button;
        public static void main(String[] args) {
                new BusyIndicatorTest();
        }
        public BusyIndicatorTest() {
                display = new Display();
                Shell shell = new Shell(display);
                shell.setText("BusyIndicatorTest");
                shell.setLayout(new FillLayout());
                
                thread = new BusyThread();
               
                button = new Button(shell, SWT.PUSH);
                button.setText("Start thread");
                button.addSelectionListener(new SelectionAdapter(){
                        public void widgetSelected(SelectionEvent e) {
                                button.setEnabled(false);
                                
                                //スレッドを渡すと自動的にそのスレッドのrun()が実行
                                BusyIndicator.showWhile(display, thread);
                                
                                button.setEnabled(true);
                        }

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

class BusyThread extends Thread {
        public void run() {
                //wait for 10 second
                for (int i = 0; i < 10; i++) {
                        System.out.println("Busy: " + i);
                        try {
                                sleep(1000);
                        } catch (InterruptedException e) {
                                e.printStackTrace();
                        }
                }
        }
}


最新更新日: 2004年10月20日
 
関連リンク
Eclipse API ドキュメント
BusyIndicator

- PR -

プレゼンテーション作成ソフト無料お試し版配信中

【Sony】大手他社よりも安い!ビジネス向け光・100Mしかも固定IP付!今なら更に初期費用最大15,000円OFF!

オフィス用品・オフィス家具 価 格 交 渉 可! 
◎ 目指せ★業界最安値 ★ ◎ オフィネット・ドットコム株式会社

注文から納品まで驚きの早さ!!【ASKULカタログ】はこちらから・・・

マイクロソフト お得な見積! まとめての購入ならオトクな方法で。ライセンスだから管理も簡単。


Copyright(C) 2003,2004 Jasmin Project. All Right Reserved.
SEO [PR] 爆速!無料ブログ 無料ホームページ開設 無料ライブ放送