|
その他
|
|
作者 岡田 一志
|
|
2008年3月28日(金曜日) 13:54 |
|
表示されている画面(アプレット)とは別にバックグラウンドで動くアプレットの作成方法をここでは紹介していきます。これにはCurlのサブアプレット機能を利用します。ここでは、バックグラウンドでタイマーを使い定期的に何か処理をするプログラムの起動・停止例を紹介します。
まずは、呼び出し側(ここではparent.curl)とバックグラウンド実行する側(ここではchild.curl)との2つの.curlファイルを用意します。child.curlの中には、以下のように通常のクラスを用意します。
|
{define-class public Child
field displayed-string:String field private timer:Timer
{constructor public {default} set self.displayed-string = "child" set self.timer = {Timer enabled? = false, interval = 1s, {on TimerEvent do {output self.displayed-string} } } }
{method public {start}:void {self.timer.enable} }
{method public {change-displayed-string str:String}:void set self.displayed-string = str }
{method public {stop}:void {self.timer.disable} } }
|
このファイルの中で、上記クラスのオブジェクト(Child)を以下のようにregister-applet-invoke-handlerを登録することで、親側から子供側のメソッドを呼び出すことができます。
{{get-the-applet}.register-applet-invoke-handler {Applet.applet-invoke-handler-for-object {Child}}, verifier = {proc {}:bool {return true}} } |
次にparent.curlでは、AppletDataを継承したクラスを作成し、child.curlを引数に指定して、そのクラスのオブジェクトを生成します。このオブジェクト(child)に対して、child.curl内のChildクラスのメソッドを実行します。メソッドを実行する際には、applet-invokeもしくはapplet-invoke-asyncを利用します。ここではバックグラウンドで実行させておきたいので、applet-invoke-asyncを利用します。
{child.applet-invoke-async finish-proc = {proc {ex:#Exception, result:any}:void}, "start" || startメソッドで、タイマー開始 } |
実行結果
child child child ...
サポートバージョン
RTE 6.0以上
サンプルコード
画面なしサブアプレットのサンプル
|
|
最終更新 ( 2008年3月28日(金曜日) 14:26 )
|