Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

Help with Timer.swing

timer

  • Please log in to reply
2 replies to this topic

#1 toto_7

toto_7

    CC Addict

  • Advanced Member
  • PipPipPipPipPip
  • 244 posts

Posted 30 November 2011 - 07:32 AM

OK, used the Timer and working fine for first part. Now I'm trying to do something else, lil bit different. In my GUI trying to have timer to show start State and end State each 2 sec. I have a method in my view that doing this job and calling it from my controller. My problem is that for a reason interface not updated (used System.out and printing ok). Here is my code in controller:

public Constructor(){
                view.showStates(view.startState); //Here calling the method to initialize Interface with Start State( Is working)
      timer = new Timer(2000, states);
      timer.start();
}

ActionListener states = new ActionListener(){

         public void actionPerformed(ActionEvent arg0) {
            if(i++%2 == 0){
               System.out.println("Start state"); //Is printed out
               view.showStates(view.startState); //Not working
            }
            else{
               System.out.println("End state"); // Is printed out
               view.showStates(view.endState); //Not working
            }
         }
         
      };


Any idea?

Thank you
toto7
  • 0

"Programming is like **. One mistake and you have to support it for the rest of your life."

-Michael Sinz

#2 lethalwire

lethalwire

    while(false){ ... }

  • Senior Member
  • PipPipPipPipPipPip
  • 766 posts
  • Programming Language:C, Java, PHP, JavaScript
  • Learning:PHP

Posted 30 November 2011 - 07:45 AM

... reason interface not updated


This makes me think of that GUI is not updating. Depending on what you're changing in the GUI, you may have to make a call to validate() or repaint() or something similar. What exactly are you trying to change in the UI?
In other words, everything is working fine, but the GUI doesn't realize that a change has been made and isn't refreshing itself to display the new date.
  • 0

#3 toto_7

toto_7

    CC Addict

  • Advanced Member
  • PipPipPipPipPip
  • 244 posts

Posted 01 December 2011 - 09:32 AM

Thanks lethalwire, that's solved the issue :)
  • 0

"Programming is like **. One mistake and you have to support it for the rest of your life."

-Michael Sinz





Also tagged with one or more of these keywords: timer

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download