Monday, 3 March 2014

Assignment no: 10
//Aim:Write a program in Java to draw a concave polygon.
import java.awt.*;
import javax.swing.*;

public class Polygon extends JFrame{
    public Polygon(){
        super("Draw Square, Rectangle, Polygon");
        setSize(400,400);
        setVisible(true);
    }

    public void paint(Graphics g){
        int xpoints[]={55,145,55,145,55};
        int ypoints[]={55,55,145,145,55};
        int npoints=5;

        int xpoints1[]={250,300,350};
        int ypoints1[]={100,50,100};
        int npoints1=3;

        Graphics2D g2d = (Graphics2D) g;
        super.paint(g);
        g.setColor(Color.red);
        g.drawRect(55,150,90,150);
        g.drawRect(150,150,200,200);
        g2d.setColor(Color.blue);
        g2d.drawLine(150,150,150,150);
        g.drawPolygon(xpoints,ypoints,npoints);
        g.drawPolygon(xpoints1,ypoints1,npoints1);
        }

    public static void main(String[] args){
        Polygon application = new Polygon();
        application.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }
}

No comments:

Post a Comment