📄 rectangle.java
字号:
/*
* 创建日期 2006-1-31
*
* TODO 要更改此生成的文件的模板,请转至
* 窗口 - 首选项 - Java - 代码样式 - 代码模板
*/
package ch6;
public class Rectangle {
private int x ;
private int y ;
private int width ;
private int height ;
public Rectangle(){
this(5,10,50,25);
x = 5;
y = 10;
width = 50;
height = 25;
}
public Rectangle(int myx, int myy,int mywidth,int myheight)
{
x=myx;
y=myy;
width=mywidth;
height=myheight;
}
public Rectangle(Point mypoint , int mywidth , int myheight ){
x = mypoint.getX();
y = mypoint.getY();
width = mywidth;
height = myheight;
}
public void setX(int ax ){
x = ax;
}
public int getX() {
return x;
}
public void setY(int ay){
x = ay;
}
public int getY() {
return y;
}
public void setWidth(int awidth ){
width = awidth;
}
public int getWidth() {
if (width > 0)
return width;
else
return 0;
}
public void setHeight(int aheight){
height = aheight;
}
public int getHeight() {
return height;
}
public int getArea()
{
return width*height;
}
public void offset(int ax , int ay ){
x = x + ax;
y = y + ay;
}
public static Rectangle Inflate(Rectangle rec , int inwidth , int inheight ){
// Rectangle1 RECT = new Rectangle1(20,30,60,50);
Rectangle RECT = new Rectangle(rec.x,rec.y,rec.width,rec.height);
RECT.x = rec.x - inwidth;
RECT.y = rec.y - inheight;
RECT.height = rec.height + 2 * inheight;
RECT.width = rec.width + 2 * inwidth;
return RECT;
}
public void Inflate(int inwidth,int inheight)
{
x=x-inwidth;
y=y-inheight;
height=height+2*inheight;
width=width+2*inwidth;
}
public void Inflate(Point p)
{
x=x-p.getX();
y=y-p.getY() ;
height=height+2*p.getY();
width=width+2*p.getX();
}
public void Inflate(Size s)
{
x=x-s.getWidth();
y=y-s.getHeight() ;
height=height+2*s.getHeight();
width=width+2*s.getHeight();
}
public String print()
{ String str;
str="X="+x+", Y="+y+"\n";
str+="Width="+width+" Height="+height+"\n";
str+=" Area="+ getArea()+"\n";
return str;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -