沒有使用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