[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
[platform-swt-dev] How to create shell level event listener and fire it in program
|
Hello,
i'm a newbe and try to develop a SWT application
to do some thing like:
a. initial the program.
b. create a shell and a listener to catch a event.
c. create a routing which add a compotion into shell
and do some thing,when it finished,fire a event to
shell.
d. when shell catch the event,do some re-initial job
and run c) again.
the code may be like (KeyEvent for eg) the code underline,
I don't know if this approach is ok,if ok how to fire the event
to shell.
thanks for an advice.
cheers,
fang
----------------------------------------------
Display display;
Shell shell;
public void main () {
display=new Display();
shell= new Shell(display);
Listener listener = new Listener() {
public void handleEvent(Event e) {
if(e.character == SWT.ESC) {
---- do something ------
processMe();
}
}
};
shell.addListener(SWT.KeyDown, listener);
shell.addListener(SWT.KeyUp, listener);
shell.open();
processMe();
while(!shell.isDisposed()){
if(!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
public void processMe() {
...... do something .....
----------
if(someEvent) {
Event e=new Event();
e.display = display;
e.widget = shell;
e.character = SWT.ESC;
KeyEvent ke = new KeyEvent(e);
{fire a key event to shell}
}
}
-----------------------------------