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
Post a Comment