Moin Jungs habe hier ein Quelltext für euch und bitte euch mir etwas darüber zu erklären zb.
-was Importet er genau ?
-was bedeutet genau dieses this, return
- wie funktioniert genau diese for schleife (hier nicht aufgeführt)
-wasruft er bei sowas auf mit dem Punkten? rect.buildRect , rect.printRect();
MFG Anderstaker
-was Importet er genau ?
-was bedeutet genau dieses this, return
- wie funktioniert genau diese for schleife (hier nicht aufgeführt)
-wasruft er bei sowas auf mit dem Punkten? rect.buildRect , rect.printRect();
Java:
1: import java.awt.Point;
2:
3: class MyRect {
4: int x1 = 0;
5: int y1 = 0;
6: int x2 = 0;
7: int y2 = 0;
8:
9: MyRect buildRect(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:
17: MyRect buildRect(Point topLeft, Point bottomRight) {
18: x1 = topLeft.x;
19: y1 = topLeft.y;
20: x2 = bottomRight.x;
21: y2 = bottomRight.y;
22: return this;
23: }
24:
25: MyRect buildRect(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:
33: void printRect(){
34: System.out.print("MyRect: <" + x1 + ", " + y1);
35: System.out.println(", " + x2 + ", " + y2 + ">");
36: }
37:
38: public static void main(String arguments[]) {
39: MyRect rect = new MyRect();
40:
41: System.out.println("Calling buildRect with coordinates 25,25,
å 50,50:");
42: rect.buildRect(25, 25, 50, 50);
43: rect.printRect();
44: System.out.println("***");
45:
46: System.out.println("Calling buildRect with points (10,10), (20,20):");
47: rect.buildRect(new Point(10,10), new Point(20,20));
48: rect.printRect();
49: System.out.println("***");
50:
51: System.out.print("Calling buildRect with 1 point (10,10),");
52: System.out.println(" width (50) and height (50):");
53:
54: rect.buildRect(new Point(10,10), 50, 50);
55: rect.printRect();
56: System.out.println("***");
57: }
58: }
MFG Anderstaker