GEOMETRY
POLYGONS
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package geometry;
//import javax.swing.JApplet;
/**
*
* @author dipantazis
*/
//public class NewJApplet extends JApplet {
/**
* Initialization method that will be called after the applet is loaded into
* the browser.
*/
// public void init() {
// TODO start asynchronous download of heavy resources
// }
// TODO overwrite start(), stop() and destroy() methods
//}
import java.awt.*;
import java.awt.event.*;
//import java.awt.print.PageFormat;
//import java.awt.print.Printable;
//import static java.awt.print.Printable.NO_SUCH_PAGE;
//import static java.awt.print.Printable.PAGE_EXISTS;
//import java.awt.print.PrinterException;
//import java.awt.print.PrinterJob;
import javax.swing.*;
public class Polygons extends JPanel {
public void paintComponent(Graphics g) {
// public static Color get HSBColor
super.paintComponent(g);
int n=7;
Polygon p1 = new Polygon();
for (int i = 0; i < n; i++)
p1.addPoint((int)
(600 + 400 * Math.cos(i * 2 * Math.PI / n)/Math.cos(Math.PI/n)),
(int) (500 + 400 * Math.sin(i * 2 * Math.PI / n)/Math.cos(Math.PI/n)));
g.setColor(Color.decode("#ffff00"));
g.fillPolygon(p1);
Polygon p = new Polygon();
for (int i = 0; i < n; i++)
p.addPoint((int)
(600 + 400 * Math.cos(i * 2 * Math.PI / n)),
(int) (500 + 400 * Math.sin(i * 2 * Math.PI / n)));
g.setColor(Color.decode("#00ff00"));
g.fillPolygon(p);
Polygon p2 = new Polygon();
for (int i = 0; i < n; i++)
p2.addPoint((int)
(600 + 200 * Math.cos(i * 2 * Math.PI / n)/Math.cos(Math.PI/n)),
(int) (500 + 200 * Math.sin(i * 2 * Math.PI / n)/Math.cos(Math.PI/n)));
g.setColor(Color.decode("#ff0000"));
g.fillPolygon(p2);
g.setColor(Color.decode("#0000ff"));
// public Color (ini,int int);
//StdDraw.setPenColor(new Color );
g.drawOval(200, 100, 800, 800);
}
public static void main(String[] args) {
JFrame frame = new JFrame();
frame.setTitle("Polygon");
frame.setSize(1200, 1000);
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
Container contentPane = frame.getContentPane();
contentPane.add(new Polygons());
frame.setVisible(true);
}
}