?? testprogressmonitor.java
字號:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
/**
* Description:
* <br/>Copyright (C), 2005-2008, Yeeku.H.Lee
* <br/>This program is protected by copyright laws.
* <br/>Program Name:
* <br/>Date:
* @author Yeeku.H.Lee kongyeeku@163.com
* @version 1.0
*/
public class TestProgressMonitor
{
Timer timer;
public void init()
{
final SimulatedTarget target = new SimulatedTarget(1000);
//以啟動一條線程的方式來執行一個耗時的任務
final Thread targetThread = new Thread(target);
targetThread.start();
//創建進度對話框
final ProgressMonitor dialog = new ProgressMonitor(null ,
"等待任務完成" , "已完成:" , 0 , target.getAmount());
//創建一個計時器
timer = new Timer(300 , new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
//以任務的當前完成量設置進度對話框的完成比例
dialog.setProgress(target.getCurrent());
//如果用戶單擊了進度對話框的”取消“按鈕
if (dialog.isCanceled())
{
//停止計時器
timer.stop();
//中斷任務的執行線程
targetThread.interrupt();
//系統退出
System.exit(0);
}
}
});
timer.start();
}
public static void main(String[] args)
{
new TestProgressMonitor().init();
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -