Posted By:
basundhara_mohanty
Posted On:
Sunday, March 26, 2006 02:33 PM
0 1 2 3 4 5 0 1 2 3 4 5 0 1 2 3 4 5 ..... ..... i need to draw the steps of a linear search like above, but whenever repaint occurs like if screen size changed or window minimised, the previous steps except for the current step.iteration are lost, that too only if i comment the super.paintComponent(g) line but as i am using swing this gives rendering problem is there any way i can save and draw all the steps? i am drawing the sta
More>>
| 0 |
1 |
2 |
3 |
4 |
5 |
| 0 |
1 |
2 |
3 |
4 |
5 |
| 0 |
1 |
2 |
3 |
4 |
5 |
.....
.....
i need to draw the steps of a linear search like above,
but whenever repaint occurs like if screen size changed or
window minimised,
the previous steps except for the current
step.iteration are lost,
that too only if i comment the
super.paintComponent(g) line
but as i am using swing this gives rendering problem
is there any way i can save and draw all the steps?
i am drawing the state of 1 iteration in a offscreen graphics
and then pasting it onto the screen,
to display the next iteration i just change the Y-coordnate
for the drawImage
...
...
public void paintComponent(Graphics g){
//super.paintComponent(g);
Dimension d=size();
startX=d.width/6;
startY=d.height/4;
if(image==null||d.width!=image.getWidth(null)||d.height!=image.getHeight(null)){
image=createImage(d.width,40);
bg=image.getGraphics();
}//
bg.setColor(Color.black);
/*draws the array as a rectangle,
and colors the rectangle of the current iteration*/
drawRects(bg);
g.drawImage(image,0,startY+(i*rectHeight,this);
}//
...
...
<<Less