SWT(JFace)體驗(yàn)之圓環(huán)狀(戒指型)
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();
}
}
相關(guān)文章
Idea運(yùn)行單個main方法,不編譯整個工程的問題
這篇文章主要介紹了Idea運(yùn)行單個main方法,不編譯整個工程的問題,具有很好的參考價(jià)值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2023-04-04springboot驗(yàn)證碼生成以及驗(yàn)證功能舉例詳解
登錄注冊是大部分系統(tǒng)需要實(shí)現(xiàn)的基本功能,同時(shí)也會對登錄驗(yàn)證增加需求,下面這篇文章主要給大家介紹了關(guān)于springboot驗(yàn)證碼生成以及驗(yàn)證功能的相關(guān)資料,需要的朋友可以參考下2023-04-04Java從零編寫吃貨聯(lián)盟訂餐系統(tǒng)全程講解
這篇文章主要介紹了Java訂餐系統(tǒng),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2022-12-12Elasticsearch QueryBuilder簡單查詢實(shí)現(xiàn)解析
這篇文章主要介紹了Elasticsearch QueryBuilder簡單查詢實(shí)現(xiàn)解析,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2019-08-08Idea之沒有網(wǎng)絡(luò)的情況下創(chuàng)建SpringBoot項(xiàng)目的方法實(shí)現(xiàn)
本文主要介紹了Idea之沒有網(wǎng)絡(luò)的情況下創(chuàng)建SpringBoot項(xiàng)目的方法實(shí)現(xiàn),文中通過圖文介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2023-09-09Java 自定義Spring框架以及Spring框架的基本使用
Spring框架是由于軟件開發(fā)的復(fù)雜性而創(chuàng)建的。Spring使用的是基本的JavaBean來完成以前只可能由EJB完成的事情。然而,Spring的用途不僅僅限于服務(wù)器端的開發(fā)2021-10-10教你開發(fā)腳手架集成Spring?Boot?Actuator監(jiān)控的詳細(xì)過程
這篇文章主要介紹了開發(fā)腳手架集成Spring?Boot?Actuator監(jiān)控的詳細(xì)過程,集成包括引入依賴配置文件及訪問驗(yàn)證的相關(guān)知識,本文給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2022-05-05Spring和MyBatis整合自動生成代碼里面text類型遇到的坑
Spring和MyBatis整合以后,使用自動生成代碼工具生成dao和mapper配置文件。下面通過本文給大家介紹Spring和MyBatis整合自動生成代碼里面text類型遇到的坑,需要的朋友參考下吧2018-01-01