java - How can i Create Color simulation with JFrame, JLabel, using setForeground? -


i doubt best way it, working currently. have these 3 jlabel objects in jpanel. 3 circles in jpanel @ font 99. left right circles colored r b g.the \u2022 circle.

endgame goal: able change circles on off. default start white. want able |r w w| or |w b g|. problem having is, want user able see colors going on , off, that's whole point. tried wait, froze program , yielded color, without transition. know going change instantly, want pause few miliseconds, or half second user can see them go on , off.

example: second 1 passes, |r w w| second 2 |w w w| second 3 |r b w| second 4 |w w w| second 5 |r w g|....etc

    ballr = new jlabel("\u2022");     panel.add(ballr);     ballr.setforeground(color.red);     ballr.setfont(new font("tahoma", font.plain, 99)); 

^^ have 1 each color, red, blue, green ^^

    private void colorred(){      ballr.setforeground(color.red);      try {         timeunit.seconds.sleep((1);     } catch (interruptedexception e) {         // todo auto-generated catch block         e.printstacktrace();     }     ballr.setforeground(color.white);  } 

i tried wait, froze program , yielded color, without transition

it unclear if calling code on edt, description sounds case - sleeping (or performing long running task) on edt using prevent repaints or listeners firing until method returns (in other words, ui locks up).

but want pause few miliseconds, or half second user can see them go on , off.

if wish perform task on edt after specified time (or repeated time interval), use timer

timer timer = new timer(500, new actionlistener(){     @override     public void actionperformed(actionevent e){         ballr.setforeground(color.white);//or red, depending     } }); timer.setrepeats(false);//don't repeat if don't want timer.start(); 

Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -