函数探讨
2015-10-25 20:56
225 查看
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 Box 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 return this; 15 } 16 Box buildBox(Point topLeft,Point bottomRight) 17 { x1 = topLeft.x; 18 y1 = topLeft.y; 19 x2 = bottomRight.x; 20 y2 = bottomRight.y; 21 return this; 22 } 23 24 25 Box buildBox(Point topLeft,int w ,int h) 26 { x1 = topLeft.x; 27 y1 = topLeft.y; 28 x2 = (x1+w); 29 y2 = (y1+h); 30 return this; 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 }
import java.awt.Point; class Box { int x1 = 0; int y1 = 0; int x2 = 0; int y2 = 0; void buildBox(int x1,int y1,int x2,int y2) { this.x1 = x1; this.y1 = y1; this.x2 = x2; this.y2 = y2; } void buildBox(Point topLeft,Point bottomRight) { x1 = topLeft.x; y1 = topLeft.y; x2 = bottomRight.x; y2 = bottomRight.y; } void buildBox(Point topLeft,int w ,int h) { x1 = topLeft.x; y1 = topLeft.y; x2 = (x1+w); y2 = (y1+h); } void printBox() { System.out.print("Box:<"+x1+","+y1); System.out.println(","+x2+","+y2+">"); } public static void main(String [] args) { Box rect = new Box(); rect.buildBox(25,25,50,50); rect.printBox(); rect.buildBox(new Point(10,10),new Point(20,20)); rect.printBox(); rect.buildBox(new Point(10,10),50,50); rect.printBox(); } }
相关文章推荐
- C++指针直接调用类成员函数探讨
- 关于将数组长度传入函数的一些探讨
- LCD浮点数显示函数的探讨
- C++指针探讨 (二)函数指针
- C++指针探讨 函数对象
- C/C++函数调用约定与函数名称修饰规则探讨
- 探讨c++函数中的参数传递与返回值(三) 函数返回值
- C++指针探讨 (二) 函数指针
- 探讨:C++中函数返回引用的注意事项
- 指针作为函数参数在C/C++中调试和探讨
- LCD浮点数显示函数的探讨
- 从函数调用的角度,探讨JavaScript中this的用法
- C/C++函数调用约定与函数名称修饰规则探讨
- C/C++函数调用约定与函数名称修饰规则探讨
- 探讨opencv函数中的mask的作用
- STM32之SystemInit()函数的探讨
- 探讨php define()函数及defined()函数使用详解
- 关与对《C语言深度解剖》函数指针的进一步探讨
- 深入探讨JS中的数组排序函数sort()和reverse()
- 深入探讨:oracle中row_number() over()分析函数用法