?? progressbar1.java
字號:
/**
* @作者:陳剛
* @Email:glchengang@yeah.net
* @Blog:http://blog.csdn.net/glchengang
*/
package swt;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.ProgressBar;
import org.eclipse.swt.widgets.Shell;
public class ProgressBar1 {
public static void main(String[] args) {
final Display display = Display.getDefault();
final Shell shell = new Shell();
shell.setSize(327, 253);
shell.setText("SWT Application");
//------------------新插入的界面核心代碼------------------------
shell.setLayout(new RowLayout());
//創(chuàng)建一個滑動條。這里用平滑型式樣SWT.SMOOTH,默認(rèn)是方格型。
final ProgressBar progressBar = new ProgressBar(shell, SWT.SMOOTH);
progressBar.setMinimum(0); //最小值
progressBar.setMaximum(100);//最大值
//創(chuàng)建一個GO按鈕
Button button = new Button(shell, SWT.BORDER);
button.setText("GO");
button.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
//每次循環(huán)progressBar前進(jìn)一格
for (int i = 1; i < 11; i++) {
try {
Thread.sleep(1000);
} catch (Throwable e2) {
} //間隔一秒
progressBar.setSelection(i * 10);
}
}
});
//------------------END---------------------------------------------
shell.layout();
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -