Digital Clock

Previous pageNext page

"Create a simple digital clock on the desktop (select next 7 lines and evaluate it with Ctrl+E)"

digitalClockProcess := [[

       Processor sleep: 1000.

       (View desktop canvas)

               font: (Font name: 'Arial' pointSize: 36) beBold;

               text: Time now printString at: 10@10;

               free

] repeat] fork.

 


This is a slightly more complex experiment. Smalltalk is a naturally multi-processing environment. In the basic development system there are already five processes running in the background. Here we are going to start another one to draw a digital clock on the screen and update it once a second. This time, because the example spans more than one line, you're going to have to select all of the lines before typing Ctrl+E (Evaluate It). Try it now. You should find that a digital display of the current time will appear in the top left-hand corner of your screen. It is rather ungraceful I'm afraid because, for simplicity, it just draws on top of any windows underneath it.

Note that, we used Evaluate It this time rather than Display It. You could have used either, it's just that the expression doesn't really answer anything sensible to display.

IMPORTANT: The above expression created a new process and placed the object for that process in a new variable called digitalClockProcess. We want to hold onto this variable so that we can destroy the clock at some point in the future (in fact it is the next experiment). So, please don't close your workspace window until you have completed the next experiment otherwise we'll lose that variable and we'll then find difficult to stop that clock ticking.

Remember, to get back to these experiments just choose Help/First Splash in any Dolphin tool window.