Timer in DWT?
Bill Baxter
wbaxter at gmail.com
Mon Sep 8 18:14:10 PDT 2008
On Tue, Sep 9, 2008 at 9:41 AM, Sam Hu <samhu.samhu at gmail.com> wrote:
> Hi Frank,
>
> For example,I want to draw a line of text on the form which indicate the current date and time,very second it changes.Below is the code I tried,when I run the program,the drawn text does not change every second if I won't resize the form.I think it is the canvas.redraw method which is the problem,but I don't know which method shoud I use instead.
> //*************************
> Display display=new Display;
> Shell shell=new Shell(display);
> Canvas canvas=new Canvas(shell,DWT.NONE);
> canvas.addPaintListener(new class PaintListener{
> public void paintControl(PaintEvent e)
> {
> auto layout=new Locale;
>
> e.gc.drawText(layout("{:ddd,dd MMMM yyyy HH':'mm':'ss z}",
> WallClock.now),100,100);
> }
> });
>
> display.getCurrent.timerExec( 500, dgRunnable({
>
> canvas.redraw;
> }));
>
> //*****************************
This only executes the timer once. You have to call timerExec again
in the delegate to get it to display again. So I think you /may/ need
to go ahead and create a Runnable subclass to make it work. Like
this:
class EverySecond : Runnable
{
void run() {
canvas.redraw;
display.getCurrent.timerExec(500, this);
}
}
That may also require you to make canvas and display members of EverySecond.
--bb
More information about the Digitalmars-d-dwt
mailing list