-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathDrawPolygons.java
46 lines (37 loc) · 1.6 KB
/
DrawPolygons.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/* Model- ... */
import edu.chalmers_gu_cse.oopd.exercises.polygonModel.PolygonModel;
import edu.chalmers_gu_cse.oopd.exercises.polygonModel.shapes.*;
/* -View- ... */
import edu.chalmers_gu_cse.oopd.exercises.view2d.PolygonViewer;
/* -Controller */
import edu.chalmers_gu_cse.oopd.exercises.controller.PolygonClicker;
public class DrawPolygons {
public static void main(String[] args) {
/* Create a new model. */
PolygonModel polygons = createModel();
/* Create a view that listens to the model and can display it. */
PolygonViewer view = createViewForModel(polygons);
/* Create a controller that sends signals to the model to create
and add new polygons.
*/
PolygonClicker controller = new PolygonClicker(polygons);
/* Make sure that the controller listens to the correct event
in the UI.
*/
controller.initInteraction(view);
polygons.animate();
}//main
public static PolygonModel createModel(){
PolygonModel polygons = new PolygonModel();
polygons.addPolygon(PolygonFactory.createSquare(50,50));
polygons.addPolygon(PolygonFactory.createTriangle(100,100));
polygons.addPolygon(PolygonFactory.createRectangle(50,150));
return polygons;
}//initModel
private static PolygonViewer createViewForModel(PolygonModel polygonModel) {
PolygonViewer view = new PolygonViewer();
view.addModel(polygonModel);
polygonModel.addListener(view);
return view;
}//initViewForModel
}//DrawPolygons