Révision 2014
tmp/org.txm.chartsengine.rcp/src/org/txm/chartsengine/rcp/tests/SWtSwingSnippet.java (revision 2014) | ||
---|---|---|
1 |
package org.txm.chartsengine.rcp.tests; |
|
2 |
|
|
3 |
import java.awt.BorderLayout; |
|
4 |
import java.awt.Frame; |
|
5 |
import java.awt.GridLayout; |
|
6 |
import java.awt.Panel; |
|
7 |
import java.awt.event.KeyAdapter; |
|
8 |
import java.awt.event.KeyEvent; |
|
9 |
|
|
10 |
import javax.swing.JLabel; |
|
11 |
import javax.swing.JRootPane; |
|
12 |
import javax.swing.JTextField; |
|
13 |
|
|
14 |
import org.eclipse.swt.SWT; |
|
15 |
import org.eclipse.swt.awt.SWT_AWT; |
|
16 |
import org.eclipse.swt.layout.FillLayout; |
|
17 |
import org.eclipse.swt.widgets.Composite; |
|
18 |
import org.eclipse.swt.widgets.Display; |
|
19 |
import org.eclipse.swt.widgets.Event; |
|
20 |
import org.eclipse.swt.widgets.Listener; |
|
21 |
import org.eclipse.swt.widgets.Shell; |
|
22 |
import org.eclipse.swt.widgets.Text; |
|
23 |
|
|
24 |
public class SWtSwingSnippet { |
|
25 |
|
|
26 |
public static void main(String[] args) { |
|
27 |
|
|
28 |
final Display display = new Display(); |
|
29 |
final Shell shell = new Shell(display); |
|
30 |
shell.setLayout(new FillLayout()); |
|
31 |
|
|
32 |
Composite composite = new Composite(shell, SWT.NO_BACKGROUND | SWT.EMBEDDED); |
|
33 |
|
|
34 |
try { |
|
35 |
System.setProperty("sun.awt.noerasebackground","true"); |
|
36 |
} catch (NoSuchMethodError error) {} |
|
37 |
|
|
38 |
/* Create and setting up frame */ |
|
39 |
Frame frame = SWT_AWT.new_Frame(composite); |
|
40 |
Panel panel = new Panel(new BorderLayout()) { |
|
41 |
public void update(java.awt.Graphics g) { |
|
42 |
paint(g); |
|
43 |
} |
|
44 |
}; |
|
45 |
frame.add(panel); |
|
46 |
JRootPane root = new JRootPane(); |
|
47 |
panel.add(root); |
|
48 |
java.awt.Container contentPane = root.getContentPane(); |
|
49 |
|
|
50 |
JLabel label1 = new JLabel("Text 1"); |
|
51 |
JTextField field1 = new JTextField(10); |
|
52 |
|
|
53 |
JLabel label2 = new JLabel("Text 2"); |
|
54 |
JTextField field2 = new JTextField(10); |
|
55 |
|
|
56 |
contentPane.setLayout(new GridLayout(2,2)); |
|
57 |
contentPane.add(label1); |
|
58 |
contentPane.add(field1); |
|
59 |
contentPane.add(label2); |
|
60 |
contentPane.add(field2); |
|
61 |
|
|
62 |
Text text = new Text(shell, SWT.BORDER); |
|
63 |
|
|
64 |
|
|
65 |
shell.setSize(200,70); |
|
66 |
shell.open(); |
|
67 |
|
|
68 |
|
|
69 |
|
|
70 |
|
|
71 |
|
|
72 |
field1.addKeyListener(new KeyAdapter() { |
|
73 |
public void keyPressed(KeyEvent e) { |
|
74 |
System.out.println("key pressed in swing"); |
|
75 |
} |
|
76 |
public void keyReleased(KeyEvent e) { |
|
77 |
System.out.println("key released in swing"); } |
|
78 |
public void keyTyped(KeyEvent e) { |
|
79 |
System.out.println("key typed in swing"); |
|
80 |
} |
|
81 |
}); |
|
82 |
display.addFilter(SWT.KeyDown,new Listener() { |
|
83 |
public void handleEvent(Event event) { |
|
84 |
System.out.println("key down in SWT"); |
|
85 |
} |
|
86 |
}); |
|
87 |
display.addFilter(SWT.KeyUp,new Listener() { |
|
88 |
public void handleEvent(Event event) { |
|
89 |
System.out.println("key up in SWT"); |
|
90 |
} |
|
91 |
}); |
|
92 |
display.addFilter(SWT.MouseMove,new Listener() { |
|
93 |
public void handleEvent(Event event) { |
|
94 |
System.out.println("mouse move in SWT"); |
|
95 |
} |
|
96 |
}); |
|
97 |
display.addFilter(SWT.MouseDown,new Listener() { |
|
98 |
public void handleEvent(Event event) { |
|
99 |
System.out.println("mouse down in SWT"); |
|
100 |
} |
|
101 |
}); |
|
102 |
display.addFilter(SWT.MouseUp,new Listener() { |
|
103 |
public void handleEvent(Event event) { |
|
104 |
System.out.println("mouse up in SWT"); |
|
105 |
} |
|
106 |
}); |
|
107 |
display.addFilter(SWT.MouseEnter,new Listener() { |
|
108 |
public void handleEvent(Event event) { |
|
109 |
System.out.println("mouse enter in SWT"); |
|
110 |
} |
|
111 |
}); |
|
112 |
|
|
113 |
while(!shell.isDisposed()) { |
|
114 |
if (!display.readAndDispatch()) display.sleep(); |
|
115 |
} |
|
116 |
display.dispose(); |
|
117 |
} |
|
118 |
} |
|
0 | 119 |
Formats disponibles : Unified diff