/*
To compile:
nicec --classpath "niceswt.jar;swt.jar" -a helloswt.jar helloswt
To run:
java -cp swt.jar;helloswt.jar helloswt.fun
*/
import nice.swt;
import nice.swt.events;
import nice.swt.layout;
import nice.swt.widgets;
void main(String[] args){
makeHelloGoodbye().open;
}
HelloGoodbye makeHelloGoodbye(){
let d = new Display();
let s = new Shell(d, SWT.TITLE | SWT.CLOSE | SWT.BORDER);
s.setLayout( new FillLayout(SWT.VERTICAL) );
s.setText(" SWT Nice Hello/Goodbye ");
s.setSize(200, 100);
let b1 = new Button(s, SWT.PUSH);
b1.setText("Hello");
let b2 = new Button(s, SWT.PUSH);
b2.setText("Goodbye");
let v =
new HelloGoodbye(
display: d,
shell: s,
helloButton: b1,
goodbyeButton: b2
);
b1.addSelectionListener( v.helloButtonSelected );
b2.addSelectionListener( v.goodbyeButtonSelected );
return v;
}
void open(HelloGoodbye v){
v.shell.open;
while (!v.shell.isDisposed) {
if (!v.display.readAndDispatch)
v.display.sleep;
}
v.display.dispose;
}
// Some prefer to separate the UI event
// handling from the UI initialization.
SelectionAdapter helloButtonSelected(HelloGoodbye v) =
new SelectionAdapter( widgetSelected: SelectionEvent e => {
if (v.helloIsReply)
v.helloButton.setText("Hello");
else
v.helloButton.setText("HELLO!");
v.helloIsReply = ! v.helloIsReply;
}
);
SelectionAdapter goodbyeButtonSelected(HelloGoodbye v) =
new SelectionAdapter( widgetSelected: SelectionEvent e => {
if (v.goodbyeIsReply)
v.goodbyeButton.setText("Goodbye");
else
v.goodbyeButton.setText("Bye!");
v.goodbyeIsReply = ! v.goodbyeIsReply;
}
);
class HelloGoodbye {
Display display;
Shell shell;
Button helloButton;
Button goodbyeButton;
boolean helloIsReply = false;
boolean goodbyeIsReply = false;
}
-- IsaacGouy - 17 Feb 2004
| Topic HelloSwtUserInterfaceExample . { Edit | Attach | Ref-By | Printable | Diffs | r1.6 | > | r1.5 | > | r1.4 | More } |
|
Revision r1.6 - 28 Apr 2005 - 11:53 GMT - TWikiGuest Parents: WebHome > CodeExamples |
Copyright © 1999-2003 by the contributing authors.
All material on this collaboration platform is the property of the contributing authors. Ideas, requests, problems regarding TWiki? Send feedback. |