Sunday, 15 June 2014

swing - How can it save the previous graphics using repaint() in java? -



swing - How can it save the previous graphics using repaint() in java? -

i need update graphic, in there rectangulars. , @ each step need highlight , modify status of of them. in code, each repaint(), draw totally new picture. have read followint similar quesion: keeping draw graphics - removing super.paintcomponent ,which cannot solve problem. next time calls repaint(), rectangulars disappear. means erases prevous graphic. please help! here code: ("firstpaint = false" before next repaint())

@override protected void paintcomponent(graphics g2) { super.paintcomponent(g2); final graphics2d g = (graphics2d) g2.create(); try{ if(firstpaint){ int status; g.setcolor(color.black); (int = 0; < rows; i++) { (int j = 0; j < columns; j++) { status = current[i][j]; if(status == 1) { g.fillrect(j * 20, * 20, 20, 20); } } } } if(executeresult == 2){ g.setcolor(color.blue); for(cell c:highlightedcells){ g.drawrect(c.j * 20, c.i * 20, 20, 20); } } if(executeresult == 1){ g.setcolor(color.red); for(cell c:highlightedcells){ g.fillrect(c.j * 20, c.i * 20, 5, 5); } } } finally{ g.dispose(); } }

java swing graphics jpanel repaint

No comments:

Post a Comment