安装Jigloo插件的步骤在此省略。
首先建一个Java项目,命名为Converter。其效果是制作出一个图形界面,向其输入一段文字,可以将此段文字倒序显示出来。
建立一个java文件,代码如下:
package main; public class Converter { public static String doConvert(String input) { String output = ""; char[] input0 = input.toCharArray(); for (int i = input0.length - 1; i >= 0; i--) { output += input0[i]; } return output; } }
然后在创建一个SWT Composite。它的本质为java文件,不过可以使用Form Editor将其转化为图形化开发界面。
使用图形开发界面,设计出下图画布布局:
使用最终代码如下:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102 |
package
main; import org.eclipse.swt.layout.FillLayout; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.Text; import org.eclipse.swt.graphics.Point; import org.eclipse.swt.graphics.Rectangle; import org.eclipse.swt.SWT; import
org.eclipse.swt.events.SelectionAdapter; import
org.eclipse.swt.events.SelectionEvent; /** * This code was edited or generated using CloudGarden‘s Jigloo SWT/Swing GUI * Builder, which is free for non-commercial use. If Jigloo is being used * commercially (ie, by a corporation, company or business for any purpose * whatever) then you should purchase a license for each developer using Jigloo. * Please visit www.cloudgarden.com for details. Use of Jigloo implies * acceptance of these licensing terms. A COMMERCIAL LICENSE HAS NOT BEEN * PURCHASED FOR THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED LEGALLY FOR * ANY CORPORATE OR COMMERCIAL PURPOSE. */ public
class NewComposite extends
org.eclipse.swt.widgets.Composite { <span style= "color: rgb(0, 0, 0);" > private
Text text1; private
Button OK; private
Text text2;</span> /** * Auto-generated main method to display this * org.eclipse.swt.widgets.Composite inside a new Shell. */ public
static void main(String[] args) { showGUI(); } /** * Overriding checkSubclass allows this class to extend * org.eclipse.swt.widgets.Composite */ protected
void checkSubclass() { } /** * Auto-generated method to display this org.eclipse.swt.widgets.Composite * inside a new Shell. */ public
static void showGUI() { Display display = Display.getDefault(); Shell shell = new
Shell(display); NewComposite inst = new
NewComposite(shell, SWT.NULL); Point size = inst.getSize(); shell.setLayout( new
FillLayout()); shell.layout(); if
(size.x == 0
&& size.y == 0 ) { inst.pack(); shell.pack(); } else
{ Rectangle shellBounds = shell.computeTrim( 0 , 0 , size.x, size.y); shell.setSize(shellBounds.width, shellBounds.height); } shell.open(); while
(!shell.isDisposed()) { if
(!display.readAndDispatch()) display.sleep(); } } public
NewComposite(org.eclipse.swt.widgets.Composite parent, int
style) { super (parent, style); initGUI(); } private
void initGUI() { try
{ this .setLayout( null ); this .setSize( 251 , 151 ); { text1 = new
Text( this , SWT.NONE); text1.setBounds( 48 , 18 , 161 , 30 ); } { text2 = new
Text( this , SWT.NONE); text2.setBounds( 48 , 71 , 161 , 30 ); } { OK = new
Button( this , SWT.PUSH | SWT.CENTER); OK.setText( "OK" ); OK.setBounds( 98 , 113 , 60 , 30 ); OK.addSelectionListener( new
SelectionAdapter() { public
void widgetSelected(SelectionEvent evt) { System.out.println( "OK.widgetSelected, event=" +evt); //TODO add your code for OK.widgetSelected <span style= "color: rgb(255, 0, 0);" >text2.setText(Converter.doConvert(text1.getText())); //此为需要手动添加的代码</span> } }); } this .layout(); } catch
(Exception e) { e.printStackTrace(); } } } |
程序的运行结果如下图:
相信自己
MyEclipsse 使用Jigloo插件开发SWT应用,布布扣,bubuko.com
原文:http://www.cnblogs.com/drl937676516/p/3579298.html