Alternative for repaint() method
807580Jan 17 2010 — edited Jan 18 2010Hello,
I am using repaint() method to redraw the components in my screen. Is there any alternative method. In the code below, i will try to explain what i am trying to do.
class Sample{
JFrame frame = new JFrame();
DrawPanel drawPanel = new DrawPanel();
frame.getContentPane().add(drawPanel);
callMethod();
....
...
.
..
}
public void callMethod()
{
///
///
//
frame.repaint(); //This will call paintComponent again, whether can i do it without repaint() [An alternative approach].
}
//This is class is in a diff file
class DrawPanel extends JPanel{
public void paintComponent(graphics g)
{
Graphics2D g2d = (Graphics2D) g;
drawRec();
}
public void drawRec()
{
g2d.fillRect(x,y,100,203);
}
}
Say on clicking a button, i want to draw rectangle with different sizes. How can i do it without calling repaint().
Please help.
Thank you.