import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

@SuppressWarnings("serial")
public class PolygonTestG extends JFrame {
	static Polygon poly1;

	private static final int W = 800;
	private static final int H = 600;

	DrawPanel drawPanel = new DrawPanel();

	public PolygonTestG() {
		super("PolygonTestG v.1.0_0");
		ActionListener listener = new AbstractAction() {
			public void actionPerformed(ActionEvent e) {
				poly1.rotate(0.1, poly1.computeCenter());
				//poly1.translate(1, -1);
				drawPanel.repaint();
			}
		};
		Timer timer = new Timer(50, listener);
		timer.start();
		
		drawPanel.setBackground(new Color(0,0,0));
		drawPanel.setForeground(new Color(0,255,0));
		
		add(drawPanel);

		pack();
		setDefaultCloseOperation(EXIT_ON_CLOSE);
		setLocationRelativeTo(null);
		setVisible(true);
	}

	private class DrawPanel extends JPanel {

		protected void paintComponent(Graphics g) {
			super.paintComponent(g);
			poly1.draw(g);
			poly1.drawString(g, 10, 10);
		}

		public Dimension getPreferredSize() {
			return new Dimension(W, H);
		}
	}

	public static void main(String[] args) {
		Point p1, p2, p3, p4, p5, p6, p7;

		p1 = new Point(3.5, 6);
		p2 = new Point(8, -1);
		p3 = new Point(4, -7);
		p4 = new Point(-3, -7);
		p5 = new Point(-4, -3);
		p6 = new Point(-4.5, 4);
		p7 = new Point(-2.5, 8.5);

		poly1 = Polygon.polygonFrom(new Point[] { p1, p2, p3, p4, p5, p6, p7 });
		
		poly1.scale(20);
		poly1.translate(W/2.0, H/2.0);

		EventQueue.invokeLater(new Runnable() {
			public void run() {
				new PolygonTestG();
			}
		});
	}
}