没有使用super.paintComponent(g);
我仍然可以清除我的Jpanel或Jframe屏幕吗?我在JPanel上绘制了一些图形,并且我想要在用户按下右键单击而不使用此方法时清除所有绘图。或者我说有super.paintCompenent(g)
的任何替代;方法或方法像clrscr();
在Java中。清除JPanel或JFrame
编辑
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();
}
}
我画这样
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);
}
后拉伸或不在您的JPanel simlpy你的代码。 – Jeffrey 2012-04-08 16:47:23
您可以调用repaint并停止调用Graphics基元。如果你有组件,那么只需调用removeAll() – 2012-04-08 16:49:35
@Jeffrey代码是什么?它太长。 – james 2012-04-08 16:49:59