SoFunction
Updated on 2025-03-08

SWT (JFace) Experience ProgressBar


package swt_jface.demo8;
import ;
import ;
import ;
import ;
import ;
import ;
import ;
import ;
import ;
import ;
import ;
import ;
import ;
import ;
public class CountNumbers {

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

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

button = new Button(shell, );
("Start to count");

progressBar = new ProgressBar(shell, );
(0);
(10);

final Thread countThread = new Thread(){
public void run() {
for(int i=0; i<=10; i++) {
final int num = i;
try {
(1000);
} catch (InterruptedException e) {
();
}
().asyncExec(new Runnable(){
public void run() {
if(() || ()) return;
("Counting: " + num);
(num);
//();
}
});
}
}
};

(, new Listener() {
public void handleEvent(Event event) {
(false);
();
}
});

(new PaintListener() {
public void paintControl(PaintEvent e) {
("PAINT");
String string = (() * 1.0 /(()-()) * 100) + "%";
Point point = ();
Font font = new Font((),"Courier",10,);
(font);
(().getSystemColor(SWT.COLOR_WHITE));
FontMetrics fontMetrics = ();
int stringWidth = () * ();
int stringHeight = ();
(string, (-stringWidth)/2 , (-stringHeight)/2, true);
();
}
});

(new GridData(GridData.FILL_HORIZONTAL));
(new GridData(GridData.FILL_HORIZONTAL));
(300, 100);
();
while (!()) {
if (!()) {
();
}
}
();
}
public static void main(String[] args) {
new CountNumbers();
}
}