import java.awt.*;
import java.awt.geom.*;
import javax.swing.*;
public class Shapes2 extends JFrame{
public Shapes2() {
super("Drawing 2D Shapes");
getContentPane().setBackground(Color.white);
setSize(500,500);
setVisible(true);
}
public void Paint(Graphics g)
{
super.paint(g);
int xpoint[]={55,67,109,73,83,55,27,37,1,43};
int ypoint[]={0,36,36,54,96,72,96,54,36,36};
Graphics2D g2d=(Graphics2D)g;
GeneralPath star= new GeneralPath();
star.moveTo(xpoint[0],ypoint[0]);
for(int count=1;count<xpoint.length;count++)
star.lineTo(xpoint[count],ypoint[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);
}
}
public static void main(String[] args) {
Shapes2 application=new Shapes2();
application.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
为什么执行这个文件时,只有一个背景为白色的窗口,我画的图怎么没显示?
import java.awt.geom.*;
import javax.swing.*;
public class Shapes2 extends JFrame{
public Shapes2() {
super("Drawing 2D Shapes");
getContentPane().setBackground(Color.white);
setSize(500,500);
setVisible(true);
}
public void Paint(Graphics g)
{
super.paint(g);
int xpoint[]={55,67,109,73,83,55,27,37,1,43};
int ypoint[]={0,36,36,54,96,72,96,54,36,36};
Graphics2D g2d=(Graphics2D)g;
GeneralPath star= new GeneralPath();
star.moveTo(xpoint[0],ypoint[0]);
for(int count=1;count<xpoint.length;count++)
star.lineTo(xpoint[count],ypoint[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);
}
}
public static void main(String[] args) {
Shapes2 application=new Shapes2();
application.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
为什么执行这个文件时,只有一个背景为白色的窗口,我画的图怎么没显示?
方法名写错 应该为
public void paint(Graphics g)
p小写另外那个图真不错