SWT(JFace)体验之打开多个Form
发布时间:2021-11-29 03:19:15
标签:SWT,Form
代码很简单,如下所示:
package swt_jface.demo1;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
public class Main {
public static void main(String[] args) {
Display display = new Display();
Image small = new Image(display, 16, 16);
GC gc = new GC(small);
gc.setBackground(display.getSystemColor(SWT.COLOR_RED));
gc.fillArc(0, 0, 16, 16, 45, 270);
gc.dispose();
Image large = new Image(display, 32, 32);
gc = new GC(large);
gc.setBackground(display.getSystemColor(SWT.COLOR_BLUE));
gc.fillArc(0, 0, 32, 32, 45, 270);
gc.dispose();
Shell shell = new Shell(display);
shell.setText("Small and Large icons");
shell.setImages(new Image[] {small, large});
Shell shell2 = new Shell(display);
shell2.setText("Small icon");
shell2.setImage(small);
shell.open();
shell2.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
}
下面是打开子画面的代码:
package swt_jface.demo1;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
public class DialogShell {
public DialogShell() {
Display display = new Display();
final Shell shell = new Shell(display);
shell.setLayout(new RowLayout());
shell.setSize(500, 200);
final Button openDialog = new Button(shell, SWT.PUSH);
openDialog.setText("Click here to rate this book ...");
openDialog.addSelectionListener(new SelectionListener() {
public void widgetSelected(SelectionEvent e) {
final Shell dialog = new Shell(shell, SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);
dialog.setLayout(new RowLayout());
final String[] ratings =
new String[] {"Killer!", "Good stuff", "So-so", "Needs work" };
final Button[] radios = new Button[ratings.length];
for (int i = 0; i < ratings.length; i++) {
radios[i] = new Button(dialog, SWT.RADIO);
radios[i].setText(ratings[i]);
}
Button rateButton = new Button(dialog, SWT.PUSH);
rateButton.setText("Rate!");
rateButton.addSelectionListener(new SelectionListener() {
public void widgetSelected(SelectionEvent e) {
for (int i = 0; i < radios.length; i++)
if (radios[i].getSelection()) openDialog.setText("Rating: " + ratings[i]);
dialog.close();
}
public void widgetDefaultSelected(SelectionEvent e) {
}
});
dialog.pack();
dialog.open();
Rectangle shellBounds = shell.getBounds();
Point dialogSize = dialog.getSize();
dialog.setLocation(shellBounds.x + (shellBounds.width - dialogSize.x) / 2, shellBounds.y + (shellBounds.height - dialogSize.y) / 2);
}
public void widgetDefaultSelected(SelectionEvent e) {
}
});
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
display.dispose();
}
public static void main(String[] args) {
new DialogShell();
}
}


猜你喜欢
- 前言我们平时在开发的时候,发起网络请求前,会需要显示一个Loading,一般的做法都是在xml布局上添加好Loading,然后在Activi
- Allatori混淆技术介绍Allatori是一个Java 混淆器,它属于第二代混淆器,因此它能够全方位地保护你的知识产权。 Allator
- 井字棋游戏要求在3乘3棋盘上,每行都相同或者每列都相同再或者对角线相同,则胜出.因此我们可以使用一个二维数组来表示棋盘,判断胜负只需要判断数
- 需求前台有日期字符串的数据,提交到后台。后台实体类使用Date属性接收。日期字符串有多种格式,需要用一个转换器将合法的日期字符串格式转换为D
- 现在的应用在注册登录或者修改密码中都用到了短信验证码,那在android中是如何实现获取短信验证码并自动填写的呢?首先,需要要在manife
- JTable的排序是一个让人头疼的问题,Sun没有为排序这个最常用的功能提供类。但是近日翻看Sun官方java的tutorial,却发现其在
- 最近在项目开发中,使用spring boot+mybatis的架构,数据库设计主键id时定义为bigint类型,使用mybatis的自动生成
- 【诞生背景】最近在做某配置中心的时候,配置中心采用properties格式进行配置的(如下图)。而我们工程的项目配置文件是yml格式的(如下
- 摘要:手把手教你使用 Java AWT 创建一个简易计算器。一、关于AWTAWT (抽象窗口工具包)是一个有助于构建 GUI 的 API (
- package com.imoyo.expert;import java.util.ArrayList;import android.app
- 无论游戏,应用,网站,都少不了评分控件。在Android SDK 中提供了 RatingBar控件来实现相应的工作。<RatingBa
- 反射机制Java语言提供的一种基础功能,通过反射,我们可以操作这个类或对象,比如获取这个类中的方法、属性和构造方法等。 * :分为JDK动
- Apache Thrift 是 Facebook 实现的一种高效的、支持多种编程语言的远程服务调用的框架。和其它RPC框架相比,它主要具有如
- 本文实例讲述了C#简单实现显示中文格式星期几的方法。分享给大家供大家参考,具体如下:1.DateTime.Now.ToString(&quo
- 今天在做数据分页显示的时候遇到了一个问题,经过测试,证实是Tomcat 6的一个bug,我所用的版本为:apache-tomcat-6.0.
- 效果图效果图依次为发现界面顶部,包含首页轮播图,水平滚动的按钮,推荐歌单;然后是发现界面推荐单曲,点击单曲就是直接进入播放界面;最后是全局播
- 1.狂妄的WPF相对传统的Windows图形编程,需要做很多复杂的工作,引用许多不同的API。例如:WinForm(带控件表单)、GDI+(
- 一、题目描述题目实现:不同的客户端之间需要进行通信,一个客户端与指定的另一客户端进行通信,实现一对一聊天功能。实现一个客户端与指定的另一客户
- Android 破解视频App去除广告功能作为一个 * 丝程序猿也有追剧的时候,但是当打开视频app的时候,那些超长的广告已经让我这个 * 丝无法忍
- Android 解决ScrollView嵌套CridView显示问题由于GridView是可滑动的控件,嵌套在ScrollView下时需要重