multithreading - Java: How should I implement waiting so that Images render? -


i'm not sure i've asked question correctly...and i'm not sure if i've relevantly phrased question or not..so, apologize in advance...but i'm quite stuck on issue , appreciate help.. further, i'm frankly not expert so...please gentle, i'm not trying idiot.

so, point of program, frankly, simple game, based off of game show on tv has lifelines.. specific 1 "phone friend" one... have quote on quote 'button' (really jpanel has mouselistener). once button pressed, add, , paint jlabel or jpanel onto jframe, whatever works draw animated gif (of countdown) , lock other components until 30 seconds have occurred. reference, not using layoutmanager @ moment...

the way i've been attempting this, is:

imageicon countdownimg = new imageicon("countdown.gif"); jlabel countdownlbl = new jlabel(countdownimg); this.getcontentpane().add(countdownlbl); countdownlbl.setlocation(200, 200); countdownlbl.setsize(new dimension(countdownimg.geticonwidth(), countdownimg.geticonheight()));  long starttime = system.currenttimemillis(); while(system.currenttimemillis() < starttime + 30000) {     ; } 

i know problem exists while loop. without loop, image renders successfully. it, java waits until after condition met render countdownlbl. i've tried creating jframe content pane had image, (probably again, due own misunderstanding or poor threading..) frame appears , not render contents. while running notice there image fetcher thread, i'm assuming bad loop interfering thread, , thread responsible rendering image.

so guess question should be...how can implement this...in thread safe way? if correct?

thank time, patience , effort.

the thread responsible drawing image icon same thread executing while loop in case.there called edt , event dispatcher thread updates swing ui.you using same edt wait countdown.

you might want swingutilities.invokelater()

edit:

should have added more information : here , using swingworker & swingutilities


Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

html - Unable to style the color of bullets in a list -

c# - must be a non-abstract type with a public parameterless constructor in redis -