?? rectangle.java
字號:
/*
* Created on 2005-1-9
*
* TODO To change the template for this generated file go to
* Window - Preferences - Java - Code Style - Code Templates
*/
package shape;
import java.awt.Point;
/**
* @author AnSen
*
* TODO To change the template for this generated type comment go to Window -
* Preferences - Java - Code Style - Code Templates
*/
public class Rectangle extends MShape{
public double x, y, width, height;
public boolean isFill = false;
public Rectangle(double x, double y, double width, double height, boolean isFill) {
this.x = x;
this.y = y;
this.width = width;
this.height = height;
this.isFill = isFill;
}
public void setLocation(double x, double y) {
this.x = x;
this.y = y;
}
public Point getPoint() {
return new Point((int)Math.ceil(x + width / 2),
(int)Math.ceil(y + height / 2));
}
public void move(double dDirect,double dDistance){
setLocation(x + Math.cos(dDirect) * dDistance, y
+ Math.sin(dDirect) * dDistance);
}
/*
* (non-Javadoc)
*
* @see shape.IShape#isSuperpose(int, int, int, int)
*/
public boolean isSuperpose(int left, int top, int width, int height) {
return false;
}
/* (non-Javadoc)
* @see shape.IShape#isAcross(double, double, double, double)
*/
public boolean isAcross(double x1, double y1, double x2, double y2) {
if (isLineAcross(x1, y1, x2, y2, x, y, x+width, y)) {
return true;
}
if (isLineAcross(x1, y1, x2, y2, x, y,x, y+ height)) {
return true;
}
if (isLineAcross(x1, y1, x2, y2, x + width, y, x + width, y + height)) {
return true;
}
if (isLineAcross(x1, y1, x2, y2, x, y + height, x + width, y + height)) {
return true;
}
return false;
}
/* (non-Javadoc)
* @see shape.IShape#isConatin(shape.IShape)
*/
public boolean isConatin(IShape shape) {
Rectangle rect=null;
if(shape instanceof Polygon){
Polygon pshp=(Polygon)shape;
rect=pshp.getBoundBox();
}else if(shape instanceof Rectangle){
rect=(Rectangle)shape;
}
if(rect.x>x&&rect.y>y&&
rect.width<width&&rect.height<height){
return true;
}else{
return false;
}
}
public Rectangle cloneShape(){
return new Rectangle(x,y,width,height,false);
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -