Example usage for java.awt Polygon Polygon

List of usage examples for java.awt Polygon Polygon

Introduction

In this page you can find the example usage for java.awt Polygon Polygon.

Prototype

public Polygon() 

Source Link

Document

Creates an empty polygon.

Usage

From source file:Main.java

public static void main(String[] argv) {
    JFrame f = new JFrame();
    f.setSize(400, 300);//from w ww  .j  a  v a2  s  .c om
    Polygon p = new Polygon();
    p.addPoint(10, 10);
    p.addPoint(100, 300);
    p.addPoint(300, 300);
    p.addPoint(10, 10);

    PolygonButton btn = new PolygonButton(p, "button");
    f.getContentPane().add(btn);
    WindowListener wndCloser = new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            System.exit(0);
        }
    };
    f.addWindowListener(wndCloser);
    f.setVisible(true);
}

From source file:SampleMethod.java

public static void main(String[] args) {
    Polygon p = new Polygon();
    showMethods(p);
}

From source file:Main.java

public void paint(Graphics g) {
    super.paintComponent(g);
    int radius = 40;
    int centerX = 50;
    int centerY = 100;

    Polygon p = new Polygon();
    centerX = 150;/*w  ww  .ja  va 2  s .co m*/
    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);

}

From source file:DrawPolyPanel.java

public void paintComponent(Graphics g) {
    super.paintComponent(g);

    Polygon p = new Polygon();
    for (int i = 0; i < 5; i++)
        p.addPoint((int) (100 + 50 * Math.cos(i * 2 * Math.PI / 5)),
                (int) (100 + 50 * Math.sin(i * 2 * Math.PI / 5)));

    g.drawPolygon(p);//from  w  w  w .  j  a  v a2  s. c om

    Polygon s = new Polygon();
    for (int i = 0; i < 360; i++) {
        double t = i / 360.0;
        s.addPoint((int) (150 + 50 * t * Math.cos(8 * t * Math.PI)),
                (int) (150 + 50 * t * Math.sin(8 * t * Math.PI)));
    }
    g.drawPolygon(s);
}

From source file:RedBlueBox.java

public void paintComponent(Graphics g) {
    Insets insets = getInsets();// www. j  a  v  a2s  .  c  om
    int endX = getWidth() - insets.right;
    int endY = getHeight() - insets.bottom;
    // get the top-left corner
    int x = insets.left;
    int y = insets.top;

    g.setColor(Color.RED);
    Polygon p = new Polygon();
    p.addPoint(x, y);
    p.addPoint(endX, y);
    p.addPoint(x, endY);
    g.fillPolygon(p);
    g.setColor(Color.BLUE);
    p.reset();
    p.addPoint(endX, y);
    p.addPoint(x, endY);
    p.addPoint(endX, endY);
    g.fillPolygon(p);
}

From source file:FillPolyPanel.java

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;/*from  w w w.j av  a 2s.  c  o  m*/
    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);
}

From source file:fungus.VisualizerTransformers.java

public static Shape createRegularPolygon(int sides, int radius) {
    Polygon p = new Polygon();
    double a = 2 * Math.PI / sides;
    for (int i = 0; i < sides; i++)
        p.addPoint((int) (radius * Math.sin(a * i)), (int) (radius * -Math.cos(a * i)));
    return p;//  www .jav  a 2 s  . c  o  m
}

From source file:org.openfaces.component.chart.impl.renderers.states.XYLineFillItemRendererState.java

public XYLineFillItemRendererState(PlotRenderingInfo info) {
    super(info);/* w  w w .  ja v a2  s.co  m*/

    areaPolygon = new Polygon();
    lines = new ArrayList<Line2D>();
}

From source file:org.openfaces.component.chart.impl.renderers.states.LineFillItemRendererState.java

public LineFillItemRendererState(PlotRenderingInfo info) {
    super(info);// w  ww . j a  v a  2 s. c om

    areaPolygon = new Polygon();
    lines = new ArrayList<Line2D>();
}

From source file:Main.java

protected void paintComponent(Graphics g) {
    super.paintComponent(g);

    g.drawLine(10, 100, 380, 100);//from   w  w w  .j a  v  a 2 s .com
    g.drawLine(200, 30, 200, 190);

    g.drawLine(380, 100, 370, 90);
    g.drawLine(380, 100, 370, 110);
    g.drawLine(200, 30, 190, 40);
    g.drawLine(200, 30, 210, 40);

    g.drawString("X", 360, 80);
    g.drawString("Y", 220, 40);

    Polygon p = new Polygon();
    Polygon p2 = new Polygon();

    for (int x = -170; x <= 170; x++) {
        p.addPoint(x + 200, 100 - (int) (50 * f((x / 100.0) * 2 * Math.PI)));

    }

    for (int x = -170; x <= 170; x++) {
        p2.addPoint(x + 200, 100 - (int) (50 * gCos((x / 100.0) * 2 * Math.PI)));

    }

    g.setColor(Color.red);
    g.drawPolyline(p.xpoints, p.ypoints, p.npoints);
    g.drawString("-2\u03c0", 95, 115);
    g.drawString("-\u03c0", 147, 115);
    g.drawString("\u03c0", 253, 115);
    g.drawString("2\u03c0", 305, 115);
    g.drawString("0", 200, 115);

    g.setColor(Color.blue);
    g.drawPolyline(p2.xpoints, p2.ypoints, p2.npoints);

}