I am really new to Java and SWT, so my question may sound silly. I looked through intrnet (and stackoverflow), but all the answers and examples are too complicated for a noob like me.
I have a class, name it Admin. When I click the button, it runs the method in another class (Handler).
- In Admin, I have a progress bar, which should increase with help in the handler.
- I donβt know how long the operation takes in the Handler, but I know that I have 9 of them.
- I would like to somehow inform the administrator about the completion of each method.
What I had so far: (inappropriate parts are missing)
Admin.java:
ProgressBar bar = new ProgressBar(this, SWT.SMOOTH); Button btn = new Button(this, SWT.NONE); btn.setText("Update"); btn.addListener(SWT.Selection, new Listener() { public void handleEvent(Event event) { btn.setEnabled(false); thread.start(); } }); Handler handler = new Handler(); final Thread thread = new Thread(){ public void run() { handler.run(); for(int i=0; i<=10; i++) { final int value = i; try { Thread.sleep(800); } catch (Exception e) { } display.asyncExec(new Runnable(){ public void run() { bar.setSelection(value); } }); } } };
Handler.java:
public class Handler implements Runnable{ void m1() {...} void m2() {...} ... void m9() {...} public void run() { m1(); m2(); ... m9(); }
With this implementation, the call to handler.run () works fine, and the progress bar fills up, but, of course, they are not "confused" in any way.
I would be grateful for your wisdom! Thank you very much!
source share