java - Why repaint() statement executes after next statement -
i want add 1 in value of x (piece.x) after repainting component repaints after adding 1 in x
what need to paint component given value (var) , change value of piece.x after repainting component
piece.x = var; repaint(); piece.x += 1 added
i have box(rectangle) moves right & left (on x axis) every second(which requires repainting) want change position(value of x-axis) of box after repainting
simply repaints box existing value of x , change value changes first , repaints
thanks !
why: repaint happens in separate thread , schedules repainting. jcomponent.paintimmediately(...); can used force repaint without scheduling in of paint queue.
piece.x = var; // happens repaint(); // schedules repaint in separate thread piece.x += 1 // isn't guaranteed happen before or after repaint some people have used time delays try , wait repaint finish before continuing execution.
it's better evaluate why need increment variable after repaint has finished , see if can change design/logic accommodate repainting happening in separate thread.
Comments
Post a Comment