java - Javax.swing timer repeats fine, but ActionListener doesn't do anything -


I am trying to flash the background color in the textfield. My timer setup is as follows:

  Flash Flash = New Flash (); // set timer TMR = new javax.swing.Timer (1000, new flash ()); Tmr.addActionListener (Flash); Tmr.setInitialDelay (0); Tmr.setRepeats (true); Tmr.start ();  

My caretaker is as follows:

  Fixed class Flash implementation ActionListener {ActionEvent evt} {if (flasher) {SpreademPanel. HistoryPnl NameTxt.setBackground (Color.white); } Other {Spread panel. HistoryPnl.NameTxt.setBackground (Color.pink); } Flasher =! Flasher; } // ActionProfile} // Flash  

Now, when I did it in debug and followed the action, the program repeatedly takes action through flash and between two options Toggles but onscreen, only the first toggle is followed, there is no action, though the flash is still working.

What's wrong with this?

Thanks in advance for any help.

Here are some problems.

The first obvious thing is that you are using a temporary situation. This is a very bad idea and points out (and the reason!) Illusion In this particular case, one of the problems is that flasher is shared steady.

  Flash Flash = New Flash (); // set timer TMR = new javax.swing.Timer (1000, new flash ()); Tmr.addActionListener (Flash);  

We are adding two flash functions usually it would be bad, but only an undetectable "bug" output color will be set twice.

Bring these two things together, and we have two verbs that Toggle the same without brakes. The state of two toggle states does not change (though there are again paint, property change incidents etc.).

So, do not use a temporary situation and keep the code clean.


Comments

Popular posts from this blog

oracle - The fastest way to check if some records in a database table? -

php - multilevel menu with multilevel array -

jQuery UI: Datepicker month format -