swing - Timer works with println but not label using java -


i have labels become visible when letter pressed.

private void formkeypressed(java.awt.event.keyevent evt) {                                     // todo add handling code here:     if(evt.getkeycode()==keyevent.vk_a){         jlabel7.setvisible(true);                     jlabel8.setvisible(true);         jlabel9.setvisible(true);         myblink();     } 

i have label8 on timer myblink()

public void myblink()     {     new timer(1000, new actionlistener() {         public void actionperformed(actionevent e) {                                 system.out.println("begin");             jlabel8.setvisible(false);             jlabel8.setvisible(true);             system.out.println("timer");         }     }).start();     } 

i have placed printlns see if timer begins , ends , when press key "a" output shows begin timer multiple times label not appear , disappear. tweak code need? missing? set of eyes.

this because call successively setvisible(false) , setvisible(true) done fast seen, should use variable , modify value time action of timer called next:

public void myblink() {     new timer(1000, new actionlistener() {         boolean visible = true;         public void actionperformed(actionevent e) {             jlabel8.setvisible(visible = !visible);         }     }).start(); } 

Comments

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -

java - Digest auth with Spring Security using javaconfig -