comparison snippets/button/Snippet108.d @ 114:0de3dab4d6e1

Add buttons snippets. Thanks TomD.
author Frank Benoit <benoit@tionex.de>
date Fri, 11 Jul 2008 21:10:38 +0200
parents
children 8cdaac0dc743
comparison
equal deleted inserted replaced
113:7194dba256b8 114:0de3dab4d6e1
1 /*******************************************************************************
2 * Copyright (c) 2000, 2004 IBM Corporation and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
7 *
8 * Contributors:
9 * IBM Corporation - initial API and implementation
10 * D Port:
11 * Thomas Demmer <t_demmer AT web DOT de>
12 *******************************************************************************/
13 module button.Snippet108;
14 /*
15 * Button example snippet: set the default button
16 *
17 * For a list of all SWT example snippets see
18 * http://www.eclipse.org/swt/snippets/
19 */
20 import dwt.DWT;
21 import dwt.widgets.Button;
22 import dwt.widgets.Display;
23 import dwt.widgets.Label;
24 import dwt.widgets.Shell;
25 import dwt.widgets.Text;
26 import dwt.events.SelectionAdapter;
27 import dwt.events.SelectionEvent;
28 import dwt.layout.RowLayout;
29 import dwt.layout.RowData;
30
31 import dwt.dwthelper.utils;
32 import tango.io.Stdout;
33
34 void main(String[] args){
35 Snippet108.main(args);
36 }
37
38 public class Snippet108 {
39
40 public static void main (String [] args) {
41 Display display = new Display ();
42 Shell shell = new Shell (display);
43 Label label = new Label (shell, DWT.NONE);
44 label.setText ("Enter your name:");
45 Text text = new Text (shell, DWT.BORDER);
46 text.setLayoutData (new RowData (100, DWT.DEFAULT));
47 Button ok = new Button (shell, DWT.PUSH);
48 ok.setText ("OK");
49 ok.addSelectionListener(new class() SelectionAdapter {
50 public void widgetSelected(SelectionEvent e) {
51 Stdout.formatln("OK");
52 }
53 });
54 Button cancel = new Button (shell, DWT.PUSH);
55 cancel.setText ("Cancel");
56 cancel.addSelectionListener(new class() SelectionAdapter {
57 public void widgetSelected(SelectionEvent e) {
58 Stdout.formatln("Cancel");
59 }
60 });
61 shell.setDefaultButton (cancel);
62 shell.setLayout (new RowLayout ());
63 shell.pack ();
64 shell.open ();
65 while (!shell.isDisposed ()) {
66 if (!display.readAndDispatch ()) display.sleep ();
67 }
68 display.dispose ();
69 }
70 }