/**Shapes2.java**Createdon2007年8月2日,上午9:39**Tochangethistemplate,chooseTools|TemplateManager*andopenthetemplateintheeditor.*//****@authoruser*/importjava.awt.*;impor...
/*
* Shapes2.java
*
* Created on 2007年8月2日, 上午9:39
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
/**
*
* @author user
*/
import java.awt.*;
import java.awt.event.*;
import java.awt.geom.*;
import javax.swing.*;
public class Shapes2 extends JFrame{
/** Creates a new instance of Shapes2 */
public Shapes2() {
super("Drawing 2D shapes");
getContentPane().setBackground(Color.yellow);
setSize(400,400);
setVisible(true);
}
public void paint(Graphics g)
{
super.paint(g);
int xPoints[]={55,67,109,73,83,55,27,37,1,43};
int yPoints[]={0,36,36,54,96,72,96,54,36,36};
Graphics2D g2d=(Graphics2D)g;
GeneralPath star=new GeneralPath();
star.moveTo(xPoints[0],yPoints[0]);
for(int count=1;count
star.lineTo(xPoints[count],yPoints[count]);
star.closePath();
g2d.translate(200,200);
for(int count=1;count<=20;count++)
{
g2d.rotate(Math.PI/10.0);
g2d.setColor(new Color((int)(Math.random()*256),
(int)(Math.random()*256),
(int)(Math.random()*256)));
g2d.fill(star);
}
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
Shapes2 application=new Shapes2();
application.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
我想问两个问题:(1) rotate()函数是否是以坐标原点为中心旋转的
(2) 对于上面那个star.closePath()这一句,删去以后效果好像是一样的.那为什么原程序要加这一句呢?
展开