Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

javax.swing.Timer stop() issue

843807Sep 20 2010 — edited Sep 20 2010
Hi,
I am developing a Web Client with Swing and have the following problem. I am polling some images from a gateway. I use a swing worker to fetch the images and a swing timer to poll. After choosing disconnect the timer has to stop and the display panel where i show the images has to be resetted.
ActionListener taskPerformer = new ActionListener(){

                    public void actionPerformed(ActionEvent e) {
                        LiveJPEGTask task = new LiveJPEGTask(gw, cam, display);
                        task.execute();
                    }

                };

                javax.swing.Timer liveTimer = new javax.swing.Timer(300, taskPerformer);
                liveTimer.start();
The problem is that after i perform stop and reset everyting in display panel the swing worker calls one more image and sets again this image at the display panel. So is it possible after i call timer.stop() to stop the executing of the swing worker?
    public void disconnectFromServer(final Gateway gateway)
    {
        Set<DisplayPanel> dpanels = timers.keySet();
        for (DisplayPanel dp: dpanels)
        {
            if(dp.getGateway()!= null)
            {
                if(dp.getGateway().equals(gateway))
                {

                    Timer t = timers.get(dp);
                    if(t.isRunning())
                    {
                        t.stop();
                        t = null;
                        dp.setCameraName("[no camera]");
                        dp.setTimestampString("");
                        dp.setImage(null, null);
                    }
                }
            }

        }
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 18 2010
Added on Sep 20 2010
3 comments
274 views