bikin bentuk bentuk graphic

import java.awt.*;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.image.BufferedImage;
import javax.swing.*;

public class DrawingArc extends JPanel {

    public DrawingArc() {
        this.setBackground(Color.CYAN);
    }

    @Override
    public void paintComponent(Graphics g) {
        super.paintComponent(g);
        g.setColor(Color.PINK);
        g.fillArc(40, 40, 100, 100, 45, 180);
        g.setFont(new Font("SansSerif", Font.BOLD, 12));
        g.setColor(Color.BLACK);
        g.drawString("ini adalah arc", 50, 65);

        Graphics2D g2 = (Graphics2D) g;
        g2.setPaint(Color.BLUE);
        g2.setStroke(new BasicStroke(11.0f));
        g2.drawOval(180, 70, 70, 100);

        BufferedImage buffImage = new BufferedImage(10, 10,
                BufferedImage.TYPE_INT_RGB);

        g2.setPaint(new TexturePaint(buffImage, new Rectangle(10, 10)));
        Graphics2D g3 = buffImage.createGraphics();
        g3.setColor(Color.BLUE);
        g3.fillRect(0, 0, 4, 4);
        g3.setColor(Color.yellow);
        g3.fillOval(0, 0, 10, 10);

        int s[] = {330, 370, 410};
        int p[] = {40, 160, 40};
        g.fillPolygon(s, p, 3);

    }

    public static void main(String args[]) {
        JFrame frame = new JFrame("Grafik 2 Dimensi");
        frame.addWindowListener(new WindowAdapter() {

            @Override
            public void windowClosing(WindowEvent e) {
                System.exit(0);
            }
        });
        frame.setLayout(new BorderLayout());
        DrawingArc da = new DrawingArc();
        frame.add(da, BorderLayout.CENTER);
        frame.setSize(450, 250);
        frame.setVisible(true);
    }
}

Komentar

Postingan populer dari blog ini

Menyesap Rindu Dalam Coding (Sastra Edan #7)

Bikin Amplop Cantik

Kost Anyar Nyah...