Presentation is loading. Please wait.

Presentation is loading. Please wait.

» The thief and house program we used last time is refactored to follow the MVC pattern » Now it consists of four parts: ˃AScene (model) ˃AThiefController.

Similar presentations


Presentation on theme: "» The thief and house program we used last time is refactored to follow the MVC pattern » Now it consists of four parts: ˃AScene (model) ˃AThiefController."— Presentation transcript:

1

2 » The thief and house program we used last time is refactored to follow the MVC pattern » Now it consists of four parts: ˃AScene (model) ˃AThiefController (controller 1) ˃AThiefMouseController (controller 2) ˃ASceneView (view) Note that at this point we do not use objectEditor to display the scene.

3 » View uses Java. awt to draw lines, images, or texts. » View extends Component. » The second property of view, BasicStroke dotted, determines the style of the output » Pay attention to the paint() method and different draw() method and their relations. » Notice that the view is an observer of the scene, so that it can update any change in the scene. » repaint() method call in propertyChange will draw the whole scene again.

4 » The button just move the thief to the right. » Notice that the button object is not the same thing as the button controller. You need to manually set the button controller as the action listener of the button. So the controller also implements ActionListener. » Once the button is pressed, it automatically call the actionPerformed() method to move the thief

5 » The mouse controller moves the thief to where the mouse click in the view. » aView.addMouseListener(this); This line enable the controller to listen to the mouse event in the view. As a Component, view naturally support addMouseListener() method. » There are a couple of different mouse events available. This program just uses mouse click event. » The event e, which is the argument of the method, contains information of the event. For example, in this program use it to retrieve the position of click.


Download ppt "» The thief and house program we used last time is refactored to follow the MVC pattern » Now it consists of four parts: ˃AScene (model) ˃AThiefController."

Similar presentations


Ads by Google