0% found this document useful (0 votes)
27 views1 page

Buat Class Lingkaran: Class Ini Berisikan Algoritma Dari Implementasi Persamaan Umum Lingkaran

This document describes a class in Java called Lingkaran (Circle) that implements the general equation for a circle. The class contains an algorithm to draw a circle using polar coordinates by calculating x and y pixel positions on a buffered image based on the center point and radius of the circle. The class overrides paintComponent to render the buffered image on a JPanel.

Uploaded by

LagaLigo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views1 page

Buat Class Lingkaran: Class Ini Berisikan Algoritma Dari Implementasi Persamaan Umum Lingkaran

This document describes a class in Java called Lingkaran (Circle) that implements the general equation for a circle. The class contains an algorithm to draw a circle using polar coordinates by calculating x and y pixel positions on a buffered image based on the center point and radius of the circle. The class overrides paintComponent to render the buffered image on a JPanel.

Uploaded by

LagaLigo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Buat Class Lingkaran

Class ini berisikan algoritma dari implementasi persamaan umum lingkaran.

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import static java.lang.Math.sqrt;
import javax.swing.JPanel;

public class Lingkaran extends JPanel {

BufferedImage gambar;

int x, y, r;

public Lingkaran(int x, int y, int r) {

this.x = x;
this.y = y;
this.r = r;
CirclePolar(x, y, r);
}

public void CirclePolar(int xc, int yc, int r){


gambar = new BufferedImage(300, 300, BufferedImage.TYPE_INT_ARGB);
double x, y;
for(double i = 1.0/r; i <= 2 * Math.PI; i += 1.0/r){
y = yc + r * Math.sin(i);
x = xc + r * Math.cos(i);
gambar.setRGB((int) x, (int) y, Color.black.getRGB());
}repaint();
}

public Dimension getPreferredSize() {


return new Dimension(gambar.getWidth(), gambar.getHeight());
}

public void paintComponent(Graphics g) {


super.paintComponent(g);
Graphics2D g2 = (Graphics2D) g;

You might also like