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

📄 circle.java

📁 JavaMapper是一个免费的Java应用程序
💻 JAVA
字号:
import java.awt.*;public class Circle extends Rect {private int origCX,origCY,nodeResize;public Circle(int x, int y) {	super(x,y);}public void draw(Graphics s) {	s.setColor(Color.blue);	if (isHighlighted() || isSelected()) {		s.setColor(Color.red);		// draw highlight lines		storeDimensions();		int r = w/2;		int a = (int)(r/Math.sqrt(2));		for (int i=0;i<2*a;i+=3) {			int X = origCX-a+i;			int Y = origCY-a+i;			int testY = (int)(r-Math.sqrt(2*Math.pow(i,2)));			int testA = (int)(Math.sqrt(Math.pow(r,2)-Math.pow(testY,2))/Math.sqrt(2));			s.drawLine(X+testA,Y-testA,X-testA,Y+testA);		}	}	if (isSelected()) {		// draw resize blocks		s.fillRect(x+w/2-3,y,7,7);  // n		s.fillRect(x+w/2-3,y+h-6,7,7);  // s		s.fillRect(x,y+h/2-3,7,7);  // w		s.fillRect(x+w-6,y+h/2-3,7,7);  // e	}	s.drawOval(x,y,w,h);}public void newPoint(int x, int y) {	x2 = x;	y2 = y;	this.h = this.w = Math.max(Math.abs(x1-x2),Math.abs(y1-y2));	if (x2>x1) this.x = x1;	else this.x = x1-this.w;		if (y2>y1) this.y = y1;	else this.y = y1-this.h;}public boolean contains(int x, int y) {	if (!(x>=this.x && x<=this.x+this.w && y>=this.y && y<=this.y+this.h)) return false;	double cx,cy,cw,ch,testx,testy;		cw = this.w/2;	ch = this.h/2;	testx = Math.abs(this.x+cw-x);	testy = Math.abs(this.y+ch-y);		cx = Math.sqrt(Math.pow(cw,2)*(1-Math.pow(testy/ch,2)));	cy = Math.sqrt(Math.pow(ch,2)*(1-Math.pow(testx/cw,2)));	if (testx == 0) cy = ch;	if (testy == 0) cx = cw;	return (testx<=cx && testy<=cy);}public void storeDimensions() {	origCX = x+w/2;	origCY = y+h/2;}public int getResize(int x, int y) {	if (checkWithin(x,y, this.x+w/2-3, this.y, this.x+w/2+3, this.y+7)) nodeResize = Frame.N_RESIZE_CURSOR; //n	else if (checkWithin(x,y, this.x+w/2-3, this.y+h-7, this.x+w/2+3, this.y+h)) nodeResize = Frame.S_RESIZE_CURSOR; //s	else if (checkWithin(x,y, this.x, this.y+h/2-3, this.x+7, this.y+h/2+3)) nodeResize = Frame.W_RESIZE_CURSOR; //w	else if (checkWithin(x,y, this.x+w-7, this.y+h/2-3, this.x+w, this.y+h/2+3)) nodeResize = Frame.E_RESIZE_CURSOR; //e	else nodeResize = Frame.DEFAULT_CURSOR;	storeDimensions();	return nodeResize;}public boolean resize (int x, int y) {	boolean r=true;	if (nodeResize==Frame.N_RESIZE_CURSOR || nodeResize==Frame.S_RESIZE_CURSOR) resizeNS(y);	else if (nodeResize==Frame.W_RESIZE_CURSOR || nodeResize==Frame.E_RESIZE_CURSOR) resizeWE(x);	else r=false;	return r;}public void resizeNS(int y) {setRadius(Math.abs(origCY-y));}public void resizeWE(int x) {setRadius(Math.abs(origCX-x));}public void setRadius(int r) {	this.x = origCX-r;	this.y = origCY-r;	this.h = this.w = r*2;}public String getType() {return "circle";}public String getCoords(String type) {	int r=w/2;	if (type=="client") return String.valueOf(x+r)+","+String.valueOf(y+r)+","+String.valueOf(r);	else if (type=="server") return String.valueOf(x+r)+","+String.valueOf(y+r)+" "+String.valueOf(x+r)+","+String.valueOf(y+2*r);	else return null;}}

⌨️ 快捷键说明

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