Jump to content

Help with Timer.swing

- - - - -

  • Please log in to reply
2 replies to this topic

#1
toto_7

toto_7

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 295 posts
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

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

-Michael Sinz

#2
lethalwire

lethalwire

    while(false){ ... }

  • Members
  • PipPipPipPipPipPipPip
  • 748 posts
  • Programming Language:Java, PHP
  • Learning:Java, PHP

toto_7 said:

... 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.

#3
toto_7

toto_7

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 295 posts
Thanks lethalwire, that's solved the issue :)

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

-Michael Sinz




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users