1 | /*
|
---|
2 | * SWT007_02.java
|
---|
3 | */
|
---|
4 |
|
---|
5 | /*
|
---|
6 | * Copyright (c) 2002, 2004 EclipseOS2 Team.
|
---|
7 | * This file is made available under the terms of the Common Public License v1.0
|
---|
8 | * which accompanies this distribution, and is available at
|
---|
9 | * http://www.eclipse.org/legal/cpl-v10.html
|
---|
10 | */
|
---|
11 |
|
---|
12 | import org.eclipse.swt.*;
|
---|
13 | import org.eclipse.swt.widgets.*;
|
---|
14 | import org.eclipse.swt.events.*;
|
---|
15 | import org.eclipse.swt.graphics.*;
|
---|
16 | import org.eclipse.swt.layout.*;
|
---|
17 |
|
---|
18 | /**
|
---|
19 | * A simple testcase that listents for key press and key release events
|
---|
20 | * (SWT.KeyEvent) ant prints the event info to the console.
|
---|
21 | */
|
---|
22 |
|
---|
23 | public class SWT007_02 extends SWTTestCase {
|
---|
24 |
|
---|
25 | static {
|
---|
26 | STEP = "007";
|
---|
27 | TEST = "02";
|
---|
28 | DESC = "Keyboard Input";
|
---|
29 | }
|
---|
30 |
|
---|
31 | public static void main (String [] args) {
|
---|
32 | go (new SWT007_02 ());
|
---|
33 | }
|
---|
34 |
|
---|
35 | Shell createTopShell (Display display) {
|
---|
36 | return new Shell (display,
|
---|
37 | SWT.SHELL_TRIM | SWT.NO_REDRAW_RESIZE);
|
---|
38 | }
|
---|
39 |
|
---|
40 | void initComponents () {
|
---|
41 | super.initComponents();
|
---|
42 |
|
---|
43 | shell.addKeyListener (new KeyListener() {
|
---|
44 | public void keyPressed (KeyEvent e) {
|
---|
45 | System.out.println( "keyPress (" + e.widget + ") :" +
|
---|
46 | " key=" + Integer.toHexString (e.keyCode) +
|
---|
47 | " char=" + Integer.toHexString (e.character) + " [" + e.character + "]" +
|
---|
48 | " mask=" + Integer.toHexString (e.stateMask)
|
---|
49 | );
|
---|
50 | }
|
---|
51 | public void keyReleased (KeyEvent e) {
|
---|
52 | System.out.println( "keyRelease (" + e.widget + ") :" +
|
---|
53 | " key=" + Integer.toHexString (e.keyCode) +
|
---|
54 | " char=" + Integer.toHexString (e.character) + " [" + e.character + "]" +
|
---|
55 | " mask=" + Integer.toHexString (e.stateMask)
|
---|
56 | );
|
---|
57 | }
|
---|
58 | });
|
---|
59 |
|
---|
60 | Rectangle dr = display.getBounds ();
|
---|
61 | Rectangle sr = new Rectangle (0, 0, 400, 300);
|
---|
62 | sr.x = (dr.width-sr.width)/2;
|
---|
63 | sr.y = (dr.height-sr.height)/2;
|
---|
64 | shell.setBounds (sr);
|
---|
65 | }
|
---|
66 |
|
---|
67 | }
|
---|
68 |
|
---|