source: trunk/tests/SWT/java/SWT002.java

Last change on this file was 12, checked in by lpino, 18 years ago
  • Initial commit
File size: 2.2 KB
RevLine 
[12]1/*
2 * SWT002.java
3 * It's just a bit enhanced o.e.swt.examples.helloworld.HelloWorld1.java
4 */
5
6/*
7 * Copyright (c) 2002, 2004 EclipseOS2 Team.
8 */
9
10/*
11 * Copyright (c) 2000, 2002 IBM Corp. All rights reserved.
12 * This file is made available under the terms of the Common Public License v1.0
13 * which accompanies this distribution, and is available at
14 * http://www.eclipse.org/legal/cpl-v10.html
15 */
16
17import java.io.PrintWriter;
18import java.io.StringWriter;
19
20import org.eclipse.swt.*;
21import org.eclipse.swt.widgets.*;
22import org.eclipse.swt.events.*;
23
24/**
25 * This example demonstrates the minimum amount of code required
26 * to open an SWT Shell and process the events.
27 */
28
29public class SWT002 extends TestCase {
30
31static {
32 STEP= "002";
33 TEST = null;
34 DESC = "Simple Shells";
35}
36
37public static void main (String [] args) {
38 go (new SWT002());
39}
40
41protected void exec() {
42 System.out.println( "OBJECTIVE: Slightly modified HelloWorld1" );
43 System.out.println( "-------------------------------------------\n" );
44
45 Display display = new Display ();
46 Shell shell = new SWT002 ().open (display);
47 while (!shell.isDisposed ()) {
48 if (!display.readAndDispatch ()) display.sleep ();
49 }
50 display.dispose ();
51}
52
53public Shell open (Display display) {
54
55 DisposeListener dl = new DisposeListener() {
56 public void widgetDisposed( DisposeEvent e )
57 {
58 System.out.println ("DisposeListener.widgetDisposed():");
59 if( e.widget instanceof Control )
60 System.out.println(" hwnd = "+
61 Integer.toHexString (((Control)e.widget).handle));
62 if( e.widget instanceof Decorations )
63 System.out.println(" title = ["+
64 ((Decorations)e.widget).getText()+"]");
65 }
66 };
67
68 Shell shell = new Shell (display);
69 shell.addDisposeListener(dl);
70 shell.setText ("SWT002: Top Shell");
71 shell.open ();
72
73 Shell shell2 = new Shell (shell);
74 shell2.addDisposeListener(dl);
75 shell2.setText ("SWT002: Secondary Shell");
76 shell2.open ();
77
78 return shell;
79}
80}
Note: See TracBrowser for help on using the repository browser.