求大神帮忙
我想实现一个五角星环绕一圈的程序,但是没有出现,求大神帮忙
package java2D;
import java.awt.*;
import java.awt.geom.*;
import java.awt.event.*;
import javax.swing.*;
public class Shapes2 extends JFrame {
public Shapes2() {
super("Draw 2D Shapes");
getContentPane().setBackground(Color.gray);
setBounds(100, 100, 400, 400);
setVisible(true);
}
public void paint(Graphics g) {
super.paint(g);
int xPoints[] =
{56, 67, 109, 73, 83, 55, 27, 37, 1, 43};
int yPoints[] =
{0, 36, 36, 54, 96, 72, 96, 54, 36, 36};
Graphics2D g2 = (Graphics2D) g;
GeneralPath star = new GeneralPath();
star.moveTo(xPoints[0], yPoints[0]);
for(int count=1; count<xPoints.length; count++)
star.lineTo(xPoints[1], yPoints[1]);
star.closePath();
g2.translate(200, 200);
for(int count=1; count<=20; count++) {
g2.rotate(Math.PI / 10.0);
g2.setColor(new Color(
(int) (Math.random() * 256),
(int) (Math.random() * 256),
(int) (Math.random() * 256)));
g2.fill(star);
}
}
public static void main(String[] args) {
Shapes2 application = new Shapes2();
application.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
------最佳解决方案--------------------for(int count=1; count<xPoints.length; count++)
star.lineTo(xPoints[1], yPoints[1]);
改为:
for(int count=1; count<xPoints.length; count++)
star.lineTo(xPoints[count], yPoints[count]);
------其他解决方案--------------------多谢了......