SWT(JFace)体验之打开多个Form

所属分类: 软件编程 / Java编程 阅读数: 96
收藏 0 赞 0 分享
代码很简单,如下所示:
复制代码 代码如下:

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();
}
}
更多精彩内容其他人还在看

Java实现文件分割和文件合并实例

本篇文章主要介绍了Java实现文件分割和文件合并实例,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
收藏 0 赞 0 分享

LeetCode -- Path Sum III分析及实现方法

这篇文章主要介绍了LeetCode -- Path Sum III分析及实现方法的相关资料,希望通过本文能帮助到大家,需要的朋友可以参考下
收藏 0 赞 0 分享

使用MUI框架构建App请求http接口实例代码

下面小编就为大家分享一篇使用MUI框架构建App请求http接口实例代码,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
收藏 0 赞 0 分享

Java发送邮箱验证码、session校验功能

本篇主要描述“发送邮箱验证码、session校验”相关前(html\js)后(java)台代码,业务逻辑示例,需要的朋友可以参考下
收藏 0 赞 0 分享

windows下 jdk1.7安装教程图解

java编程的初学者在开始编码前都会遇到一个难题,那就是jdk1.7环境变量配置怎么操作,怎么安装,针对这个难题,小编特地为大家整理相关教程,不了解的朋友可以前往查看使用
收藏 0 赞 0 分享

JAVA演示阿里云图像识别API,印刷文字识别-营业执照识别

最近有由于工作需要,开始接触阿里云的云市场的印刷文字识别API-营业执照识别这里我加上了官网的申请说明,只要你有阿里云账号就可以用,前500次是免费的,API说明很简陋,只能做个简单参考
收藏 0 赞 0 分享

springboot 使用yml配置文件给静态变量赋值教程

这篇文章主要介绍了springboot 使用yml配置文件给静态变量赋值教程,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
收藏 0 赞 0 分享

关于springboot 配置文件中属性变量引用方式@@解析

这篇文章主要介绍了关于springboot 配置文件中属性变量引用方式@@解析,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
收藏 0 赞 0 分享

springboot yml定义属性,下文中${} 引用说明

这篇文章主要介绍了springboot yml定义属性,下文中${} 引用说明,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
收藏 0 赞 0 分享

IDEA解决Java:程序包xxxx不存在的问题

这篇文章主要介绍了IDEA解决Java:程序包xxxx不存在的问题,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下
收藏 0 赞 0 分享
查看更多