问题在于绘制矩形之后我在18个矩形的外侧创建的较大圆的中心有圆圈。在这个问题中,这18个矩形的左下角必须是通用的,并且之间没有空格中心的矩形。我怎样才能删除这个空间。它必须由drawPolygon函数绘制。感谢帮助,对不起我的英语!
import java.awt.*;
import javax.swing.*;
public class Rect20degreeRotate extends JApplet{
public void init() {
resize(500,500);
Container DrawArea = getContentPane();
DrawArea.add(
new JPanel(){
public void paintComponent(Graphics g) {
Graphics2D g2 = (Graphics2D)g;
int x[]={10,40,40,10};
int y[]={10,10,20,20};
g2.translate( 100, 100);
for (int i=0;i<18;i++){
g2.rotate(20.0 * Math.PI / 180.0);
g2.drawPolygon(x,y,4);
}
}
}
);
}
}
答案 0 :(得分:0)
import java.awt.*;
import javax.swing.*;
public class Rect20degreeRotate extends JApplet{
public void init() {
resize(500,500);
Container DrawArea = getContentPane();
DrawArea.add(
new JPanel(){
public void paintComponent(Graphics g) {
Graphics2D g2 = (Graphics2D)g;
int x[]={0,80,80,0};
int y[]={0,0,50,50};
g2.translate( 100, 100);
for (int i=0;i<18;i++){
g2.rotate(20.0 * Math.PI / 180.0);
g2.drawPolygon(x,y,4);
}
}
}
);
}
}