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

Last change on this file was 12, checked in by lpino, 18 years ago
  • Initial commit
File size: 1.9 KB
Line 
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
12import org.eclipse.swt.*;
13import org.eclipse.swt.widgets.*;
14import org.eclipse.swt.events.*;
15import org.eclipse.swt.graphics.*;
16import 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
23public class SWT007_02 extends SWTTestCase {
24
25static {
26 STEP = "007";
27 TEST = "02";
28 DESC = "Keyboard Input";
29}
30
31public static void main (String [] args) {
32 go (new SWT007_02 ());
33}
34
35Shell createTopShell (Display display) {
36 return new Shell (display,
37 SWT.SHELL_TRIM | SWT.NO_REDRAW_RESIZE);
38}
39
40void 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
Note: See TracBrowser for help on using the repository browser.