⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 nonrectangularclass.java

📁 eclipse cookbook the source code of the book
💻 JAVA
字号:
package org.cookbook.ch08;

import org.eclipse.swt.*;
import org.eclipse.swt.graphics.*;
import org.eclipse.swt.widgets.*;

public class NonRectangularClass {
	
	static int[] createCircle(int xOffset, int yOffset, int radius) {
		int[] circlePoints = new int[10 * radius];
		for (int loopIndex = 0; loopIndex < 2 * radius + 1; loopIndex++) {
			int xCurrent = loopIndex - radius;
			int yCurrent = (int) Math.sqrt(radius * radius - xCurrent * xCurrent);
			int doubleLoopIndex = 2 * loopIndex;
			
			circlePoints[doubleLoopIndex] = xCurrent + xOffset;
			circlePoints[doubleLoopIndex + 1] = yCurrent + yOffset;
			circlePoints[10 * radius - doubleLoopIndex - 2] = xCurrent + xOffset;
			circlePoints[10 * radius - doubleLoopIndex - 1] = -yCurrent + yOffset;
		}
		
		return circlePoints;
	}
	
	public static void main(String[] args) {
		final Display display = new Display();
		final Shell shell = new Shell(display, SWT.NO_TRIM);
		
		Region region = new Region();
		region.add(createCircle(50, 50, 50));
		region.subtract(createCircle(50, 50, 20));
		shell.setRegion(region);
		shell.setSize(region.getBounds().width, region.getBounds().height);
		shell.setBackground(display.getSystemColor(SWT.COLOR_BLUE));
		
		Button button = new Button(shell, SWT.PUSH);
		button.setText("Exit");
		button.setBounds(35, 6, 35, 20);
		button.addListener(SWT.Selection, new Listener() {
			public void handleEvent(Event event) {
				shell.close();
			}
		});
		
		shell.open();
		while (!shell.isDisposed()) {
			if (!display.readAndDispatch())
				display.sleep();
		}
		region.dispose();
		display.dispose();
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -