Without using super.paintComponent(g); can i still clear my Jpanel or Jframe Screen? I have some shapes drawn on JPanel and i want to clear all the drawing when user presses the right click without Using this method. or i say is there any alternate of super.paintCompenent(g);method or method like clrscr(); In Java.
EDIT
public void mousePressed(MouseEvent e) {
super.paintComponents(null); //i want to use this method here?? how can i?
if(e.isPopupTrigger())
{
s=e.getX();
as=e.getY();
try {
Thread.sleep(10L);
} catch (InterruptedException ex) {
Logger.getLogger(animate.class.getName()).log(Level.SEVERE, null, ex);
}
p.repaint();
}
}
i am painting the shape like this
public class mypanel extends JPanel {
@Override
public void paintComponent(Graphics g)
{
super.paintComponent(g);
Graphics2D g2=(Graphics2D)g ;
Color[] c = {Color.BLUE, Color.RED, Color.GREEN, Color.YELLOW,
Color.MAGENTA, Color.WHITE, Color.ORANGE, Color.PINK};
for(int i=0; i<8; ++i){
g2.setColor(c[i]);
int start_angle=i*45;
g2.fillArc(mx-100, my-100, 200, 200, start_angle,45);
}
mre solution is actually a good idea, but you may have issues if another repaint comes in (because you move the JFrame, because you resize it, because another window comes on top of it and then leavs, etc…)
Alternatively, you can have something like this to make the change permanent:
And then you can just draw or not in your JPanel simlpy by calling mypanel.setDraw(boolean)