标签:
1 1 import java.awt.Point; 2 2 3 3 class Box 4 4 { int x1 = 0; 5 5 int y1 = 0; 6 6 int x2 = 0; 7 7 int y2 = 0; 8 8 9 9 Box buildBox(int x1,int y1,int x2,int y2) 10 10 { this.x1 = x1; 11 11 this.y1 = y1; 12 12 this.x2 = x2; 13 13 this.y2 = y2; 14 14 return this; 15 15 } 16 16 Box buildBox(Point topLeft,Point bottomRight) 17 17 { x1 = topLeft.x; 18 18 y1 = topLeft.y; 19 19 x2 = bottomRight.x; 20 20 y2 = bottomRight.y; 21 21 return this; 22 22 } 23 23 24 24 25 25 Box buildBox(Point topLeft,int w ,int h) 26 26 { x1 = topLeft.x; 27 27 y1 = topLeft.y; 28 28 x2 = (x1+w); 29 29 y2 = (y1+h); 30 30 return this; 31 31 } 32 32 void printBox() 33 33 { 34 34 System.out.print("Box:<"+x1+","+y1); 35 35 System.out.println(","+x2+","+y2+">"); 36 36 } 37 37 public static void main(String [] args) 38 38 39 39 { Box rect = new Box(); 40 40 rect.buildBox(25,25,50,50); 41 41 rect.printBox(); 42 42 rect.buildBox(new Point(10,10),new Point(20,20)); 43 43 rect.printBox(); 44 44 rect.buildBox(new Point(10,10),50,50); 45 45 rect.printBox(); 46 46 47 47 48 48 49 49 } 50 50 51 51 52 52 53 53 }
1 import java.awt.Point; 2 3 class Box 4 { int x1 = 0; 5 int y1 = 0; 6 int x2 = 0; 7 int y2 = 0; 8 9 void buildBox(int x1,int y1,int x2,int y2) 10 { this.x1 = x1; 11 this.y1 = y1; 12 this.x2 = x2; 13 this.y2 = y2; 14 15 } 16 void buildBox(Point topLeft,Point bottomRight) 17 { x1 = topLeft.x; 18 y1 = topLeft.y; 19 x2 = bottomRight.x; 20 y2 = bottomRight.y; 21 22 } 23 24 25 void buildBox(Point topLeft,int w ,int h) 26 { x1 = topLeft.x; 27 y1 = topLeft.y; 28 x2 = (x1+w); 29 y2 = (y1+h); 30 31 } 32 void printBox() 33 { 34 System.out.print("Box:<"+x1+","+y1); 35 System.out.println(","+x2+","+y2+">"); 36 } 37 public static void main(String [] args) 38 39 { Box rect = new Box(); 40 rect.buildBox(25,25,50,50); 41 rect.printBox(); 42 rect.buildBox(new Point(10,10),new Point(20,20)); 43 rect.printBox(); 44 rect.buildBox(new Point(10,10),50,50); 45 rect.printBox(); 46 47 48 49 } 50 51 52 53 }
标签:
原文地址:http://www.cnblogs.com/lubocsu/p/4909550.html