30 views
Skip to first unread message

Aldin Habibović

unread,
Dec 26, 2012, 5:36:42 AM12/26/12
to google-web-toolkit
Hi guys,

How to achieve digital time in GWT.  I try this code:


final TextBox textBox = new TextBox();

     Timer t = new Timer() {
           
            @Override
            public void run() {                 
                  textBox.setText(new Date()+"");
            }
        };
        t.schedule(1000);

but didn't work. Please help.

Arian Gerryts

unread,
Dec 26, 2012, 1:48:40 PM12/26/12
to google-we...@googlegroups.com
I did a simlar thing once where I used swing components

something like

label = new JLabel();

       

        pane.add(label);
        add(pane);
        sdf = new SimpleDateFormat("HH:mm:ss");
        date = new Date();

        s = sdf.format(date);
        label.setText(s);
        setVisible(true);
        runner = new Thread(this);

        while(runner == null)
        {
            runner = new Thread(this);
            runner.start();

        }

and then

public void run() { while(true) { try { Thread.sleep(1000); sdf = new SimpleDateFormat("HH:mm:ss"); date = new Date(); s = sdf.format(date); label.setText(s); } catch(Exception e){} }



--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To post to this group, send email to google-we...@googlegroups.com.
To unsubscribe from this group, send email to google-web-tool...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.

Aldin Habibović

unread,
Dec 26, 2012, 4:20:37 PM12/26/12
to google-web-toolkit
Yes, in my previous code I just had to add t.scheduleRepeating(1000); instead t.schedule(1000);

Jens

unread,
Dec 26, 2012, 4:47:36 PM12/26/12
to google-we...@googlegroups.com
Scheduler.get().scheduleFixedPeriod() is what you want.

-- J.
Reply all
Reply to author
Forward
0 new messages