/**
来 自 时 代 J a v a 公 众 号 - nowjava.com
**/
import java.awt.Point;
public class Main {
int x1 = 0;
int y1 = 0;
int x2 = 0;
int y2 = 0;
Main(int x1, int y1, int x2, int y2) {
this.x1 = x1;
this.y1 = y1;
this.x2 = x2;
this.y2 = y2;
}
Main(Point topLeft, Point bottomRight) {
this(topLeft.x, topLeft.y, bottomRight.x,/**来 自 时 代 J a v a - nowjava.com**/
bottomRight.y);
}
Main(Point topLeft, int w, int h) {
this(topLeft.x, topLeft.y, topLeft.x + w,
topLeft.y + h);
}
void printBox() {
System.out.print("Box: <" + x1 + ", " + y1);
System.out.println(", " + x2 + ", " + y2 + ">");
}
public static void main(String[] arguments) {
Main rect;
System.out.println("Calling Box2 with coordinates "
+ "(25,25) and (50,50):");
rect = new Main(25, 25, 50, 50);
rect.printBox();
System.out.println("\nCalling Box2 with points "
+ "(10,10) and (20,20):");
rect= new Main(new Point(10, 10), new Point(20, 20));
/**代码未完, 请加载全部代码(NowJava.com).**/
本文系作者在时代Java发表,未经许可,不得转载。如有侵权,请联系nowjava@qq.com删除。