28
|
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 org.eclipse.swt.snippets.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 org.eclipse.swt.SWT;
|
|
21 import org.eclipse.swt.widgets.Button;
|
|
22 import org.eclipse.swt.widgets.Display;
|
|
23 import org.eclipse.swt.widgets.Label;
|
|
24 import org.eclipse.swt.widgets.Shell;
|
|
25 import org.eclipse.swt.widgets.Text;
|
|
26 import org.eclipse.swt.events.SelectionAdapter;
|
|
27 import org.eclipse.swt.events.SelectionEvent;
|
|
28 import org.eclipse.swt.layout.RowLayout;
|
|
29 import org.eclipse.swt.layout.RowData;
|
|
30
|
|
31 import java.lang.all;
|
|
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, SWT.NONE);
|
|
44 label.setText ("Enter your name:");
|
|
45 Text text = new Text (shell, SWT.BORDER);
|
|
46 text.setLayoutData (new RowData (100, SWT.DEFAULT));
|
|
47 Button ok = new Button (shell, SWT.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, SWT.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 }
|
|
71
|