Essential ActionScript 2.0
Authors: Moock C.
Published year: 2004
Pages: 138-139/177
Buy this book on amazon.com >>
 <  Day Day Up  >  

18.4 Further Exploration

Because our clock is an MVC application, it is incredibly flexible. New interfaces, input responses, and functionality can easily be added to the clock. If you're keen to experiment with MVC in ActionScript, try the following exercises:

  • Create a view that can display a different time zone.

  • Create a new view that displays a creative representation of the hours, minutes, and seconds of the clock ”perhaps use shapes on screen to represent the time: circles for the hours, triangles for the minutes, and squares for the seconds.

  • Create a new view that makes a ticking sound every second and, at the top of every hour , gongs to indicate the current time.

  • Add components to the ClockTools view that let the user set the current time.

  • Change the ClockModel so that it updates by polling the computer's system time instead of by counting milliseconds with setInterval( ) . Hint: you'll need the Date( ) class.

  • Change the clock so it can display hundredths of a second, like a stopwatch.

  • Let the user set the time by dragging the analog hands or editing the digital display.

If you'd like to continue reading about the MVC design pattern, see the following online articles:


Steve Burbeck's canonical Applications Programming in Smalltalk-80(TM): How to use Model-View-Controller (MVC)

http://st-www.cs.uiuc.edu/users/smarch/st-docs/mvc.html


John Hunt's You've got the model-view-controller ( excellent article with complete example source in Java)

http://www.jaydeetechnology.co.uk/planetjava/tutorials/swing/Model-View-Controller.PDF


Richard Baldwin 's Implementing The Model-View-Controller Paradigm using Observer and Observable

http://www.dickbaldwin.com/java/Java200.htm


Sun's Java BluePrints: Model-View-Controller

http://java.sun.com/blueprints/patterns/MVC-detailed.html

In the next (and final) chapter, we'll continue our coverage of interclass update mechanisms by studying the delegation event model.

 <  Day Day Up  >  
 <  Day Day Up  >  

Chapter 19. The Delegation Event Model

[In the delegation event model,] an event is propagated from a "Source" object to a "Listener" object by invoking a method on the listener and passing in the instance of the event subclass which defines the event type generated.

”from Sun's Java AWT: Delegation Event Model (http://java.sun.com/j2se/1.4.1/docs/guide/awt/1.3/designspec/events.html)

In Chapter 16, we used the Observer pattern to structure a group of objects so that when one changes state, the others are automatically notified. As we learned in Chapter 16, the Observer pattern is intentionally generic, emphasizing loose coupling between the object that changes (the subject ) and the objects being notified of the change (the observers ). In this chapter, we'll apply the concepts of the Observer pattern to a more specific situation: implementing events for a class. Our event implementation will follow Java's delegation event model , a general design for event broadcasting.

The delegation event model framework we'll develop in this chapter can be used to implement event broadcasting for any class. For example, a Chat class might use it to implement onChatMessage( ) or onUserNameChanged( ) events. An interactive WorldMap class might likewise implement onCountryClick( ) , onCountryRollover( ), and onCountryRollout( ) events. Or a ChessGame class might implement onCheckMate( ) , onPieceTaken( ) , and onMove( ) events. In each case, the delegation event model provides a basic structure for the event source ( Chat , WorldMap , and ChessGame ) and the event listeners (objects that register to receive events from an event source).

As usual, the code discussed in this chapter is available at http:// moock .org/eas2/examples.

 <  Day Day Up  >  
Essential ActionScript 2.0
Authors: Moock C.
Published year: 2004
Pages: 138-139/177
Buy this book on amazon.com >>

Similar books on Amazon