演示代码:
int[] buatLingkaran(int radius, int centerX, int centerY) {
int[] poin = int baru[360 * 2];
untuk(int i=0; i<360; i++) {
poin[i*2] = centerX + (int)(radius * Math.cos(Math.toRadians(i)));
poin[i*2+1] = pusatY + (int)(radius * Math.sin(Math.toRadians(i)));
}
poin pengembalian;
}
Poin originalPosition = null;
RingShell publik() {
tampilan tampilan akhir = tampilan baru();
shell Shell terakhir = Shell baru(tampilan, SWT.NO_TRIM | SWT.ON_TOP);
shell.setBackground(display.getSystemColor(SWT.COLOR_DARK_MAGENTA));
Wilayah wilayah = Wilayah baru();
wilayah.tambahkan(buatLingkaran(100, 100, 100));
wilayah.kurangi(buatLingkaran(50, 100, 100));
shell.setRegion(wilayah);
shell.addMouseListener(MouseListener baru() {
public void mouseDoubleClick(MouseEvent e) {
tampilan.buang();
}
public void mouseDown(MouseEvent e) {
originalPosition = Titik baru(misal, ey);
}
public void mouseUp(MouseEvent e) {
Posisi asli = null;
}
});
shell.addMouseMoveListener(MouseMoveListener baru() {
public void mouseMove(MouseEvent e) {
if(posisi asli == null) kembali;
Titik titik = display.map(shell, null, ex, ey);
shell.setLocation(point.x - originalPosition.x, point.y - originalPosition.y);
System.out.println("Pindah dari: " + Posisi asli + " ke " + titik);
}
});
RegionBounds persegi panjang = region.getBounds();
shell.setSize(regionBounds.width, regionBounds.height);
shell.open();
while (!shell.isDisposition()) {
if (!display.readAndDispatch()) {
tampilan.tidur();
}
}
tampilan.buang();
wilayah.buang();
}
public static void main(String[] args) {
RingShell baru();
}
}