Eclipse WindowBuilder(SWT)插件安装及初次使用(萌新)

一、插件安装

(有VPN的挂VPN,服务器在外网更新下载比较慢)

1.首先更新到最新版本

点击Help,点击check for update,右下角显示查询进度,查询完毕会显示最新版内容。全部更新

2.还是在help内,点击eclipse marketplacea,搜索windowbuilder插件,安装。这个是图形化界面编程,内置swt和swing。我们用swt

二、创建project

  1. 在project explorer新建“other project”,快捷键ctrl+N,找到SWT/JFace java Project

点开,右键src,新建other

 依次点击WindowsBuilder—SWT Designer—SWT—Application Window

   空Project:

底部Source是源码,Design是图形化编程。Design里拖动组件,在源码中会同时显现代码。一般来说,在design中拖动组件(如按钮、文本框)等,然后添加监听(如点击等),运行的功能在source中给出代码

(更多用处还不清楚,今天第一天下载)

这边建议可以先看狂神的gui编程:

https://www.bilibili.com/video/BV1DJ411B75F?spm_id_from=333.337.search-card.all.click

虽然主要讲的是awt和swing但很多原理是共通的

二、自己摸索写了个gui计算a+b

很简单,三个label三个文本框,一个按钮。全都是可以拖动的

背景图片我没有找到在design中直接添加的办法,用代码添加。(随便挑了个图过来)

这个shell就是窗口数值代码

2.按钮监听

右键按钮组件,按上图添加监听。我随便选了个双击。

选完之后,返回source查看源代码,会发现多出一些代码:

中间就是要写当你双击时执行的代码

我写的是双击后执行A+B,同时不允许输入空格。

由于文本框输入都是String所以计算时多次强制转换。我认为应该还有更好的方式完成a+b这个简单的操作。哎

3.初次之外,还写了个文本框监听,让你无法输入英文和符号

下图为第一个文本框的监听,第二个相同,改一下文本框名字就行

4.自动换行

数字一长就会超出文本框显示,所以加了个自动换行的style

最终效果:

总结流程:design设计界面,并添加监听,执行代码得自己去source里写。

四、小结

有点gui基础会很轻松,不过后面老师应该也会交所以不急

网上关于swt下载安装教程太少了,(不过swt内实现一些功能的操作教学还是有不少的,可以ctrlcv了)文字版很多有问题。视频几乎没有。本文主要写一下下载方式和我第一天玩玩的基础操作。东西特别多,得慢慢学。

代码:

  1 package testSWT;
2
3 import org.eclipse.swt.widgets.Display;
4 import org.eclipse.swt.widgets.Shell;
5 import org.eclipse.swt.widgets.Label;
6 import org.eclipse.jface.window.Window;
7 import org.eclipse.swt.SWT;
8 import org.eclipse.swt.widgets.Text;
9 import org.eclipse.swt.layout.GridLayout;
10 import org.eclipse.swt.custom.StackLayout;
11 import org.eclipse.swt.layout.FormLayout;
12 import org.eclipse.ui.forms.widgets.FormToolkit;
13 import org.eclipse.swt.widgets.Button;
14 import org.eclipse.swt.events.MouseAdapter;
15 import org.eclipse.swt.events.MouseEvent;
16 import org.eclipse.swt.widgets.Composite;
17 import org.eclipse.wb.swt.SWTResourceManager;
18 import org.eclipse.ui.forms.widgets.ImageHyperlink;
19 import org.eclipse.swt.widgets.Menu;
20 import org.eclipse.swt.widgets.MenuItem;
21 import org.eclipse.swt.events.MouseWheelListener;
22 import org.eclipse.swt.events.SelectionAdapter;
23 import org.eclipse.swt.events.SelectionEvent;
24 import org.eclipse.swt.events.VerifyListener;
25 import org.eclipse.swt.events.VerifyEvent;
26
27 public class testSWTAPP {
28
29 protected Shell shell;
30 private final FormToolkit formToolkit = new FormToolkit(Display.getDefault());
31 private Text txtNewText;
32 private Text txtNewText_1;
33 private Text txtNewText_2;
34
35 /**
36 * Launch the application.
37 * @param args
38 */
39 public static void main(String[] args) {
40 try {
41 testSWTAPP window = new testSWTAPP();
42 window.open();
43 } catch (Exception e) {
44 e.printStackTrace();
45 }
46 }
47
48 /**
49 * Open the window.
50 */
51 public void open() {
52 Display display = Display.getDefault();
53 createContents();
54 shell.open();
55 shell.layout();
56 while (!shell.isDisposed()) {
57 if (!display.readAndDispatch()) {
58 display.sleep();
59 }
60 }
61 }
62
63 /**
64 * Create contents of the window.
65 */
66 protected void createContents() {
67 shell = new Shell(SWT.CLOSE|SWT.MIN);
68 shell.setImage(SWTResourceManager.getImage("C:\\Users\\wenwen\\Desktop\\CXTKZ026UV(LIF7]]YFG)CW.png"));
69 shell.setSize(466, 539);
70 shell.setText("Testing SWT...");
71 shell.setLayout(null);
72 shell.setBackgroundImage(SWTResourceManager.getImage("C:\\Users\\wenwen\\Desktop\\CXTKZ026UV(LIF7]]YFG)CW.png"));
73
74 Button button = formToolkit.createButton(shell, "\uFF08\u53CC\u51FB\uFF09\u6C42\u548C", SWT.NONE);
75
76
77 button.setForeground(SWTResourceManager.getColor(SWT.COLOR_LINK_FOREGROUND));
78 button.addMouseListener(new MouseAdapter() {
79 @Override
80 public void mouseDoubleClick(MouseEvent e) {
81 int flag = 0;
82 String A = txtNewText.getText();
83 if(A.contains(" "))flag=1;
84 String B= txtNewText_1.getText();
85 if(B.contains(" "))flag=1;
86
87 if(flag==1) {
88 txtNewText_2.setText("error,别tm输入空格啊小崽子");
89 }
90 else {
91 double a =Double.parseDouble(txtNewText.getText());
92 double b =Double.parseDouble(txtNewText_1.getText());
93 double c=a+b;String C=Double.toString(c);
94 txtNewText_2.setText(C);
95 }
96 }
97 });
98
99 button.setBounds(147, 372, 167, 34);
100
101 txtNewText = formToolkit.createText(shell,"", SWT.WRAP | SWT.MULTI);
102 txtNewText.addVerifyListener(new VerifyListener() {
103 public void verifyText(VerifyEvent e) {
104
105 try {
106 // 以Text中已经输入的内容创建StringBuffer对象
107 StringBuffer buffer = new StringBuffer(txtNewText.getText());
108 // 删除e.start, e.end指定范围的内容
109 // 并将要插入的内容e.text插入指定的位置,模拟输入e.text后Text对象中的内容
110 // 末尾添一个0,以保证buffer中只有一个字符为且为+-.时,不会触发NumberFormatException
111 buffer.delete(e.start, e.end).insert(e.start, e.text).append('0');
112 // 尝试将buffer中的内容转换成Float,如果不抛出异常说明输入内容有效
113 Double.valueOf(buffer.toString());
114 } catch (NumberFormatException ex) {
115 e.doit=false;
116 }
117 }
118 });
119 txtNewText.setBounds(259, 90, 151, 30);
120
121
122
123
124
125
126 txtNewText_1 = formToolkit.createText(shell, "", SWT.WRAP | SWT.MULTI);
127 txtNewText_1.addVerifyListener(new VerifyListener() {
128 public void verifyText(VerifyEvent e) {
129
130 try {
131 // 以Text中已经输入的内容创建StringBuffer对象
132 StringBuffer buffer = new StringBuffer(txtNewText_1.getText());
133 // 删除e.start, e.end指定范围的内容
134 // 并将要插入的内容e.text插入指定的位置,模拟输入e.text后Text对象中的内容
135 // 末尾添一个0,以保证buffer中只有一个字符为且为+-.时,不会触发NumberFormatException
136 buffer.delete(e.start, e.end).insert(e.start, e.text).append('0');
137 // 尝试将buffer中的内容转换成Float,如果不抛出异常说明输入内容有效
138 Double.valueOf(buffer.toString());
139 } catch (NumberFormatException ex) {
140 e.doit=false;
141 }
142 }
143 });
144 txtNewText_1.setBounds(259, 189, 151, 30);
145
146
147 txtNewText_2 = formToolkit.createText(shell, "", SWT.WRAP | SWT.MULTI);
148 txtNewText_2.setText("");
149 txtNewText_2.setBounds(259, 254, 151, 83);
150
151 Label lblA = formToolkit.createLabel(shell, "a:", SWT.CENTER);
152 lblA.setBackground(SWTResourceManager.getColor(SWT.COLOR_YELLOW));
153 lblA.setBounds(107, 93, 90, 24);
154
155 Label lblB = formToolkit.createLabel(shell, "b:", SWT.CENTER);
156 lblB.setBackground(SWTResourceManager.getColor(SWT.COLOR_YELLOW));
157 lblB.setBounds(107, 192, 90, 24);
158
159 Label lblA_1_1 = formToolkit.createLabel(shell, "a+b:", SWT.CENTER);
160 lblA_1_1.setBackground(SWTResourceManager.getColor(SWT.COLOR_YELLOW));
161 lblA_1_1.setBounds(107, 290, 90, 24);
162
163 }
164 }

Eclipse WindowBuilder(SWT)插件安装及初次使用记录(萌新)的更多相关文章

  1. eclipse maven plugin 插件 安装 和 配置

      离线插件 点击下载离线安装包:eclipse-maven-plugin.zip ( for eclipse helios or higher ) .解压缩到任意目录(如这里的plugins目录): ...

  2. 最详细eclipse汉化插件安装教程

    最详细eclipse汉化插件安装教程(转) 转自:http://blog.csdn.net/dai_zhenliang/article/details/8588576#t4 教程作者:戴振良 本文与& ...

  3. eclipse中jetty插件安装

    注:本文来源于:<eclipse中jetty插件安装> 一.eclipse中jetty插件安装: 打开eclipse,依次点击菜单Help->Eclipse Marketplace, ...

  4. Eclipse MyBatis Generator插件安装

    目录 Eclipse MyBatis Generator插件安装 Eclipse MyBatis Generator插件安装 1.进入Eclipse Marketplace [Help] -> ...

  5. 笔记:eclipse的findbugs插件安装成功却不显示

    关键字:findbugs eclipse的findbugs插件安装成功却不显示的原因有: 1.插件版本太高,低版本的eclipse不兼容 2.也有可能是JDK版本低 findbugs安装方法: 1.在 ...

  6. Ubuntu系统---C++之Eclipse编译器 CDT插件安装

                                                                                         Ubuntu系统---Ecli ...

  7. Eclipse常用的插件安装

    嫌公司用的eclipse不爽,准备自己弄一个,diy的,没想到装插得烦死人. 诱惑人的“常用插件”: (1)    AmaterasUML        介绍:Eclipse的UML插件,支持UML活 ...

  8. Eclipse的SVN插件安装

    两种方法: 首先下载安装到eclipse的svn插件包,包里会有“plugins”和“features”两个文件夹,安装时要用到. 1.然后找到eclipse目录下的同名文件夹“plugins”和“f ...

  9. eclipse的svn插件安装方式

    eclipse的插件安装一般有3种方式: 1)通过eclipse的Help/ Install New Software...中, 点击Add, 添加一个在线更新地址,如:http://subclips ...

  10. Java开发环境配置(3)--eclipse汉化插件安装、卸载 中遇到的问题

    eclipse汉化中遇到的问题 网上汉化的帖子很多 如: Eclipse超级完美汉化教程_百度经验http://jingyan.baidu.com/article/e75057f28401a8ebc9 ...

随机推荐

  1. Win10在WSL上使用Vivado对ZCU 102 PYNQ进行ILA调试

    ZCU 102上有两个USB接口(接口信号均为micro-A),其中靠近角落的接口为jtag端口,另外一个是uart端口 vivado自带的硬件管理器通过jtag端口连接到开发板.启动开发板,连接开发 ...

  2. jmeter参数化CSV文件内容为中文读取乱码的问题

    如下图,若CSV文件内的参数为中文时候,jmeter在读取数据时会显示为乱码且不可用 这里与创建CSV参数文件的编码格式有关系 系统自带的编码方式只有红圈内几项,只有编码格式为GBK时,才支持读取中文 ...

  3. Vue ElementUI 树表格

    树表格做懒加载-点击小箭头走接口 children为[]则使用hasChildren的true/false来判断是否有子节点,另,如果要做点击小箭头走接口必须加lazy及load <el-tab ...

  4. 用c#从头写一个AI agent,实现企业内部自然语言数据统计分析

    1.本文目的 不借助任何框架,使用c#写一个agent,实现调用阿里千问大模型完成预定任务.同时完成一个可扩展的agent框架雏形. 2.预期读者 本文假设读者已经了解了一些基本概念,例如AI,fun ...

  5. bat文件备份数据库

    @echo off/*获取当前日期*/ set "Ymd=%date:~,4%%date:~5,2%%date:~8,2%" /*数据库自带的备份脚本的存放地址 --opt -u ...

  6. C#之并发字典

    internal class Program { const string Item = "Dictionary item"; const int Iterations = 100 ...

  7. 记录一次maven依赖冲突的解决

    现象 项目依赖selenium-java的4.32版本,但是未发现org.openqa.selenium.devtools.DevTools类.如下所示: 问题排查 定位问题 第一反应肯定是依赖冲突了 ...

  8. OpenDeepWiki:让您的代码仓库拥有MCP变成Agents的一部分!!

    想象一下,如果您的代码仓库突然有了生命,能够自己介绍自己.回答问题.甚至还能生成漂亮的文档,那会是什么样的场景?别以为这是科幻小说,OpenDeepWiki就是这样一个神奇的"代码翻译官&q ...

  9. Qt图像处理技术四:图像二值化

    Qt图像处理技术四:图像二值化 github 如果你觉得有用的话,期待你的小星星 实战应用项目: github :https://github.com/dependon/simple-image-fi ...

  10. 创建Spring Boot项目时,提示 Cannot download 'https://start.spring.io'

    问题提出 在使用IDEA创建Spring Boot项目时,提示无法连接https://start.spring.io,内容如下: Cannot download 'https://start.spri ...