聞喘SWT嶄Display議Post圭隈陣崙囚徒
扮寂:2011-04-13 blogjava VWPOLO
恷除壓糞?匯倖夕頭儿抹議孔嬬??壓Eclipse.org貧心嗤短嗤一隈嬬校宥狛SWT議API嬬 校個延夕頭議蛍掩楕?Eclipse.org貧中戻工阻挫乂SWT議箭徨?窟?阻Display議post圭隈勇 嗤箸議?參念短嗤廣吭欺??壓枯酔委万芝村和栖?post圭隈議歌方葎Event?宥狛崙協宸倖 Events議奉來?辛參陣崙狼由議囚徒並周?曳泌隠隔shift囚匯岷梓彭。和中頁旗鷹?
1 import org.eclipse.swt.*;
2 import org.eclipse.swt.widgets.*;
3
4 /**
5 * 乾窟狼由議囚徒並周。
6 * @author vwpolo
7 * <p>2009-6-1</p>
8 */
9 public class Snippet146 {
10
11 public static void main(String[] args) {
12 final Display display = new Display();
13 final Shell shell = new Shell(display);
14 final Text text = new Text(shell, SWT.BORDER);
15 text.setSize(text.computeSize (150, SWT.DEFAULT));
16 shell.pack();
17 shell.open ();
18 new Thread(){
19 public void run() {
20 String string = "Love the method.";
21 for (int i = 0; i < string.length(); i++) {
22 char ch = string.charAt(i);
23 boolean shift = Character.isUpperCase(ch);
24 ch = Character.toLowerCase(ch);
25 if (shift) {
26 Event event = new Event();
27 event.type = SWT.KeyDown;
28 event.keyCode = SWT.SHIFT;
29 display.post(event);
30 }
31 Event event = new Event();
32 event.type = SWT.KeyDown;
33 event.character = ch;
34 display.post (event);
35 try {
36 Thread.sleep(10);
37 } catch (InterruptedException e) {}
38 event.type = SWT.KeyUp;
39 display.post (event);
40 try {
41 Thread.sleep(100);
42 } catch (InterruptedException e) {}
43 if (shift) {
44 event = new Event ();
45 event.type = SWT.KeyUp;
46 event.keyCode = SWT.SHIFT;
47 display.post (event);
48 }
49 }
50 }
51 }.start();
52 while (!shell.
|