您的位置:首页 > 其它

函数探讨

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();

}

}

 

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: