SWT(JFace)体验之圆环状(戒指型)

所属分类: 软件编程 / java 阅读数: 67
收藏 0 赞 0 分享
演示代码:
复制代码 代码如下:

package swt_jface.demo1;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.events.MouseListener;
import org.eclipse.swt.events.MouseMoveListener;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.graphics.Region;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
public class RingShell {

int[] createCircle(int radius, int centerX, int centerY) {
int[] points = new int[360 * 2];
for(int i=0; i<360; i++) {
points[i*2] = centerX + (int)(radius * Math.cos(Math.toRadians(i)));
points[i*2+1] = centerY + (int)(radius * Math.sin(Math.toRadians(i)));
}
return points;
}

Point originalPosition = null;
public RingShell() {

final Display display = new Display();
final Shell shell = new Shell(display, SWT.NO_TRIM | SWT.ON_TOP);
shell.setBackground(display.getSystemColor(SWT.COLOR_DARK_MAGENTA));

Region region = new Region();
region.add(createCircle(100, 100, 100));
region.subtract(createCircle(50, 100, 100));
shell.setRegion(region);

shell.addMouseListener(new MouseListener() {
public void mouseDoubleClick(MouseEvent e) {
display.dispose();
}
public void mouseDown(MouseEvent e) {
originalPosition = new Point(e.x, e.y);
}
public void mouseUp(MouseEvent e) {
originalPosition = null;
}
});

shell.addMouseMoveListener(new MouseMoveListener() {
public void mouseMove(MouseEvent e) {
if(originalPosition == null) return;
Point point = display.map(shell, null, e.x, e.y);
shell.setLocation(point.x - originalPosition.x, point.y - originalPosition.y);
System.out.println("Moved from: " + originalPosition + " to " + point);
}
});

Rectangle regionBounds = region.getBounds();
shell.setSize(regionBounds.width, regionBounds.height);
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
display.dispose();
region.dispose();
}

public static void main(String[] args) {
new RingShell();
}
}
更多精彩内容其他人还在看

Javaweb 鼠标移入移出表格颜色变化的实现

这篇文章主要介绍了Javaweb 鼠标移入移出表格颜色变化的实现,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
收藏 0 赞 0 分享

Java 实现图片压缩的两种方法

这篇文章主要介绍了Java 实现图片压缩的两种方法,帮助大家更好的理解和使用Java,感兴趣的朋友可以了解下
收藏 0 赞 0 分享

据说这个是可以撸到2089年的idea2020.2(推荐)

这篇文章主要介绍了据说这个是可以撸到2089年的idea2020.2,本教程给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下
收藏 0 赞 0 分享

一篇文章带你搞定SpringBoot不重启项目实现修改静态资源

这篇文章主要介绍了一篇文章带你搞定SpringBoot不重启项目实现修改静态资源,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
收藏 0 赞 0 分享

win10操作系统下重启电脑java环境变量失效

这篇文章主要介绍了win10操作系统下重启电脑java环境变量失效,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
收藏 0 赞 0 分享

Java实现批量修改文件名和重命名的方法

这篇文章主要介绍了Java实现批量修改文件名和重命名的方法,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
收藏 0 赞 0 分享

关于Java HashMap自动排序的简单剖析

这篇文章主要给大家介绍了关于Java HashMap自动排序的简单剖析,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
收藏 0 赞 0 分享

Spring中BeanFactory和ApplicationContext的作用和区别(推荐)

这篇文章主要介绍了Spring中BeanFactory和ApplicationContext的作用和区别,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下
收藏 0 赞 0 分享

Java程序执行Cmd指令所遇问题记录及解决方案

这篇文章主要介绍了Java程序执行Cmd指令所遇问题记录,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下
收藏 0 赞 0 分享

深入浅析jni中的java接口使用

这篇文章主要介绍了jni中的java接口使用,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下
收藏 0 赞 0 分享
查看更多