Sun Oct 26, 2008 3:56 am
Sun Oct 26, 2008 10:14 am
import java.awt.Container;
import java.awt.Graphics;
import java.awt.Polygon;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class FillPolyPanel extends JPanel {
public void paintComponent(Graphics g) {
super.paintComponent(g);
int radius = 40;
int centerX = 50;
int centerY = 100;
int angle = 30;
int dx = (int) (radius * Math.cos(angle * Math.PI / 180));
int dy = (int) (radius * Math.sin(angle * Math.PI / 180));
g.fillArc(centerX - radius, centerY - radius, 2 * radius, 2 * radius, angle, 360 - 2 * angle);
Polygon p = new Polygon();
centerX = 150;
for (int i = 0; i < 5; i++)
p.addPoint((int) (centerX + radius * Math.cos(i * 2 * Math.PI / 5)),
(int) (centerY + radius * Math.sin(i * 2 * Math.PI / 5)));
g.fillPolygon(p);
p = new Polygon();
centerX = 250;
for (int i = 0; i < 360; i++) {
double t = i / 360.0;
p.addPoint((int) (centerX + radius * t * Math.cos(8 * t * Math.PI)),
(int) (centerY + radius * t * Math.sin(8 * t * Math.PI)));
}
g.fillPolygon(p);
}
public static void main(String[] args) {
JFrame frame = new JFrame();
frame.setTitle("FillPoly");
frame.setSize(300, 200);
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
Container contentPane = frame.getContentPane();
contentPane.add(new FillPolyPanel());
frame.show();
}
}
Mon Oct 27, 2008 2:56 am
/**draw truck*/
//draw tires
g.fillOval(76,393,48,48);
g.fillOval(238,397,44,48);
//draw windshield
g.drawArc(200,250,75,100,0,90);
g.drawLine(275,325,274,300);
g.drawLine(200,250,245,251);
//draw truck body
g.setColor(myGreen);
int xs[]={40,40,200,200,225,225,320,325,
285,265,255,240,120,105,95,80};
int ys[]={400,325,325,250,250,325,325,
400,400,390,390,400,400,390,390,400};
int pts=xs.length;
g.fillPolygon(xs,ys,pts);
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com
Powered by phpBB © phpBB Group.