Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Alternative for repaint() method

807580Jan 17 2010 — edited Jan 18 2010
Hello,

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.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Feb 15 2010
Added on Jan 17 2010
10 comments
549 views