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

public class shape extends JFrame implements ActionListener {
    JButton b[] = new JButton[10];
    int in;

    public shape() {
        setLayout(new FlowLayout());
        b[0] = new JButton("Line");
        b[1] = new JButton("Rectangle");
        b[2] = new JButton("FilledRectangle");
        b[3] = new JButton("RoundedRectangle");
        b[4] = new JButton("FilledRoundedRectangle");
        b[5] = new JButton("Oval");
        b[6] = new JButton("FilledOval");
        b[7] = new JButton("Arc");
        b[8] = new JButton("FilledArc");
        b[9] = new JButton("Polygon");

        for (int i = 0; i < 10; i++) {
            add(b[i]);
            b[i].addActionListener(this);
        }

        setSize(400, 310);
        setVisible(true);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }

    public void actionPerformed(ActionEvent ae) {
        for (int j = 0; j < 10; j++) {
            if (ae.getSource() == b[j]) {
                in = j + 1;
                break;
            }
        }
        repaint();
    }

    public void paint(Graphics g) {
        super.paint(g);
        if (in == 1)
            g.drawLine(150, 150, 250, 300);
        if (in == 2)
            g.drawRect(150, 150, 60, 50);
        if (in == 3)
            g.fillRect(150, 150, 60, 50);
        if (in == 4)
            g.drawRoundRect(150, 150, 60, 50, 15, 15);
        if (in == 5)
            g.fillRoundRect(150, 150, 60, 50, 15, 15);
        if (in == 6)
            g.drawOval(150, 150, 60, 50);
        if (in == 7)
            g.fillOval(150, 150, 60, 50);
        if (in == 8)
            g.drawArc(150, 150, 60, 50, 0, 75);
        if (in == 9)
            g.fillArc(150, 150, 60, 50, 0, 75);
        if (in == 10) {
            int xpoints[] = {50, 200, 250, 250, 200};
            int ypoints[] = {250, 200, 250, 300, 300};
            int num = 5;
            g.drawPolygon(xpoints, ypoints, num);
        }
    }

    public static void main(String[] args) {
        new shape();
    }
}

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: