欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

SWT(JFace)體驗(yàn)之ProgressBar

 更新時(shí)間:2009年06月25日 11:44:22   作者:  
SWT(JFace)體驗(yàn)之ProgressBar 實(shí)現(xiàn)代碼。
先看代碼:
ProgressBarExamples.java
復(fù)制代碼 代碼如下:

package swt_jface.demo8;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.PaintEvent;
import org.eclipse.swt.events.PaintListener;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.FontMetrics;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.ProgressBar;
import org.eclipse.swt.widgets.Shell;
public class ProgressBarExamples {

Display display = new Display();
Shell shell = new Shell(display);
public ProgressBarExamples() {
ProgressBar pb1 = new ProgressBar(shell, SWT.NULL);
final ProgressBar pb2 = new ProgressBar(shell, SWT.SMOOTH);
ProgressBar pb3 = new ProgressBar(shell, SWT.INDETERMINATE);

pb2.addPaintListener(new PaintListener() {
public void paintControl(PaintEvent e) {
Point point = pb2.getSize();

Font font = new Font(shell.getDisplay(),"Courier",10,SWT.BOLD);
e.gc.setFont(font);
e.gc.setForeground(shell.getDisplay().getSystemColor(SWT.COLOR_WHITE));

FontMetrics fontMetrics = e.gc.getFontMetrics();
int stringWidth = fontMetrics.getAverageCharWidth() * 4;
int stringHeight = fontMetrics.getHeight();

e.gc.drawString("60%", (point.x-stringWidth)/2 , (point.y-stringHeight)/2, true);
font.dispose();
}
});

pb1.setSelection(60);
pb2.setSelection(60);

pb1.setBounds(100, 10, 200, 20);
pb2.setBounds(100, 40, 200, 20);
pb3.setBounds(100, 70, 200, 20);

Label label = new Label(shell, SWT.NULL);
label.setText("(default)");
Label label2 = new Label(shell, SWT.NULL);
label2.setText("SWT.SMOOTH");

label.setAlignment(SWT.RIGHT);
label2.setAlignment(SWT.RIGHT);
label.setBounds(10, 10, 80, 20);
label2.setBounds(10, 40, 80, 20);

shell.pack();
shell.open();

while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
display.dispose();
}
public static void main(String[] args) {
new ProgressBarExamples();
}
}

再來一個(gè)例子:
CountNumbers.java
復(fù)制代碼 代碼如下:

package swt_jface.demo8;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.PaintEvent;
import org.eclipse.swt.events.PaintListener;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.FontMetrics;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.ProgressBar;
import org.eclipse.swt.widgets.Shell;
public class CountNumbers {

Display display = new Display();
Shell shell = new Shell(display);
Button button;
ProgressBar progressBar;

public CountNumbers() {
GridLayout gridLayout = new GridLayout(1, true);
shell.setLayout(gridLayout);

button = new Button(shell, SWT.BORDER);
button.setText("Start to count");

progressBar = new ProgressBar(shell, SWT.SMOOTH);
progressBar.setMinimum(0);
progressBar.setMaximum(10);

final Thread countThread = new Thread(){
public void run() {
for(int i=0; i<=10; i++) {
final int num = i;
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
shell.getDisplay().asyncExec(new Runnable(){
public void run() {
if(button.isDisposed() || progressBar.isDisposed()) return;
button.setText("Counting: " + num);
progressBar.setSelection(num);
//progressBar.redraw();
}
});
}
}
};

button.addListener(SWT.Selection, new Listener() {
public void handleEvent(Event event) {
button.setEnabled(false);
countThread.start();
}
});

progressBar.addPaintListener(new PaintListener() {
public void paintControl(PaintEvent e) {
System.out.println("PAINT");
String string = (progressBar.getSelection() * 1.0 /(progressBar.getMaximum()-progressBar.getMinimum()) * 100) + "%";
Point point = progressBar.getSize();
Font font = new Font(shell.getDisplay(),"Courier",10,SWT.BOLD);
e.gc.setFont(font);
e.gc.setForeground(shell.getDisplay().getSystemColor(SWT.COLOR_WHITE));
FontMetrics fontMetrics = e.gc.getFontMetrics();
int stringWidth = fontMetrics.getAverageCharWidth() * string.length();
int stringHeight = fontMetrics.getHeight();
e.gc.drawString(string, (point.x-stringWidth)/2 , (point.y-stringHeight)/2, true);
font.dispose();
}
});

button.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
progressBar.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
shell.setSize(300, 100);
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
display.dispose();
}
public static void main(String[] args) {
new CountNumbers();
}
}

相關(guān)文章

  • Java中Iterator與ListIterator迭代的區(qū)別

    Java中Iterator與ListIterator迭代的區(qū)別

    本文主要介紹了Java中Iterator與ListIterator迭代的區(qū)別,文中通過示例代碼介紹的非常詳細(xì),需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2021-07-07
  • idea配置多環(huán)境啟動(dòng)方式dev、test、prod

    idea配置多環(huán)境啟動(dòng)方式dev、test、prod

    這篇文章主要介紹了idea配置多環(huán)境啟動(dòng)方式dev、test、prod,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2023-09-09
  • JavaEE通過response實(shí)現(xiàn)請(qǐng)求重定向

    JavaEE通過response實(shí)現(xiàn)請(qǐng)求重定向

    這篇文章主要介紹了JavaEE通過response實(shí)現(xiàn)請(qǐng)求重定向的方法,非常的簡(jiǎn)單實(shí)用,有需要的朋友可以參考下
    2014-10-10
  • java中單雙斜杠的使用圖文詳解

    java中單雙斜杠的使用圖文詳解

    JAVA中的斜杠有正斜杠與反斜杠之分,正斜杠,一般就叫做斜杠,下面這篇文章主要給大家介紹了關(guān)于java中單雙斜杠使用的相關(guān)資料,文中通過圖文介紹的非常詳細(xì),需要的朋友可以參考下
    2022-09-09
  • 淺析java中ArrayList與Vector的區(qū)別以及HashMap與Hashtable的區(qū)別

    淺析java中ArrayList與Vector的區(qū)別以及HashMap與Hashtable的區(qū)別

    以下是對(duì)java中ArrayList與Vector的區(qū)別以及HashMap與Hashtable的區(qū)別進(jìn)行了詳細(xì)的解析。需要的朋友可以過來參考下
    2013-08-08
  • Java源碼解析ThreadLocal及使用場(chǎng)景

    Java源碼解析ThreadLocal及使用場(chǎng)景

    今天小編就為大家分享一篇關(guān)于Java源碼解析ThreadLocal及使用場(chǎng)景,小編覺得內(nèi)容挺不錯(cuò)的,現(xiàn)在分享給大家,具有很好的參考價(jià)值,需要的朋友一起跟隨小編來看看吧
    2019-01-01
  • 通俗講解JVM的類加載機(jī)制

    通俗講解JVM的類加載機(jī)制

    這篇文章主要介紹了JVM的類加載機(jī)制的相關(guān)資料,幫助大家更好的理解和學(xué)習(xí)Java,感興趣的朋友可以了解下
    2020-09-09
  • 解析Java格式字符串的使用

    解析Java格式字符串的使用

    本文通過實(shí)例給大家介紹了java格式字符串的使用,代碼簡(jiǎn)單易懂,對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友參考下吧
    2022-02-02
  • 詳解在Java程序中運(yùn)用Redis緩存對(duì)象的方法

    詳解在Java程序中運(yùn)用Redis緩存對(duì)象的方法

    這篇文章主要介紹了在Java程序中運(yùn)用Redis緩存對(duì)象的方法,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2019-03-03
  • SpringBoot配置圖片訪問的虛擬路徑

    SpringBoot配置圖片訪問的虛擬路徑

    大家好,本篇文章主要講的是SpringBoot配置圖片訪問的虛擬路徑,感興趣的同學(xué)趕快來看一看吧,對(duì)你有幫助的話記得收藏一下
    2022-02-02

最新評(píng)論