具體而言,我試圖只顯示旋轉的對象。我有一個繪製的矩形,我旋轉它。如何在java graphics2D中旋轉後刪除原始對象?
如何只顯示旋轉的矩形並處理舊的?
編輯:
以下是轉動我的矩形代碼:
private void rotateRectangle(Graphics g, Rectangle rect, Color c){
Graphics2D g2d = (Graphics2D) g.create();
x = rect.x;
y = rect.y;
g2d.setColor(c);
g2d.rotate(Math.PI/6, PANEL_WIDTH/2,PANEL_HEIGHT/2);
g2d.drawRect(PANEL_WIDTH/2-x/2, PANEL_HEIGHT/2-y/2, x, y);
}
這是的paintComponent,我把它從:
@Override
public void paintComponent(Graphics g) {
super.paintComponent(g);
Graphics2D g2d = (Graphics2D) g.create();
g2d.setStroke(new BasicStroke(3));
//these are declared before
rect.x = x;
rect.y = y;
if(rotateClicked){
rotateRectangle(g2d,rect,squareColor);
rotateClicked = false;
}
drawRectangle(g2d, rect, squareColor);
getArea(x,y);
}
請分享您用於繪製和旋轉對象的代碼。如果您希望社羣努力回答您的問題,則需要努力解決您的問題。 –
仔細查看[在AWT和Swing中繪畫](http://www.oracle.com/technetwork/java/painting-140037.html)和[執行自定義繪畫](http://docs.oracle.com/javase/tutorial/uiswing/painting /)獲取關於繪畫在Swing中的工作原理的詳細信息 – MadProgrammer
@Zoltán我認爲這將有一個快速解決方案,這就是爲什麼我沒有提供代碼,無論如何我現在編輯帖子以包括我迄今爲止的所有 – kvito