Clock Applet
The applet uses the Java library classes Thread, Font, Calendar, Date and Graphics.
importClass: Applet java.applet.Applet importClass: Thread java.lang.Thread importClass: Graphics java.awt.Graphics importClass: Font java.awt.Font importClass: Calendar java.util.Calendar importClass: Date java.util.Date importInterface: Runnable java.lang.Runnable importMethod: setTime Calendar setTime ( date -- ) importMethod: calendarGet Calendar get ( int -- int ) importMethod: setFont Graphics setFont ( font -- ) importMethod: drawString Graphics drawString ( string int int -- ) importMethod: repaint Applet repaint ( -- ) importMethod: startThread Thread start ( -- ) importMethod: stopThread Thread stop ( -- ) importMethod: sleep Thread sleep ( long -- ) static importField: hourOfDay Calendar HOUR_OF_DAY int stativ importField: second Calendar SECOND int static importField: minute Calendar MINUTE int static importField: italic Font ITALIC int static importField: bold Font BOLD int public class: Clock extends Applet implements Runnable static Calendar clockCalendar Thread clockThread static Font clockFont i: clock.<init> ( -- ) InitSuper () ; i: clock.init ( -- ) CalendarInstance =: clockCalendar " TimesRoman" italic bold + 100 new clockFont ( string int int -- ) ; \ The browser creates an object of class clock and calls start(). The \ object (this) is also an object of Runnable. i: clock.start ( -- ) this new Thread ( runnable -- ) =: clockThread clockThread startThread ; \ Delivers the int value of the current hour. : hours ( -- int ) HourOfDay clockCalendar calendarGet ; : minutes ( -- int ) Minute clockCalendar CalendarGet ; : seconds ( -- int ) Second clockCalendar CalendarGet ; : clockTimeString ( -- string ) new Date () clockCalendar setTime <# seconds # # drop ascii : hold minutes # # drop ascii : hold hours # # #> ; \ Applet.repaint calls update, which clears the graphics and calls paint. \ Overlays applet.paint. i: clock.paint ( Graphics graf -- ) clockFont graf setFont clockTimeString 40 100 graf DrawString ; i: clock.run ( -- ) begin this repaint 1000. sleep again ; i: clock.stop ( -- ) ClockThread stopThread ;