Membuat Lingkaran, Garis Lurus, Persegi pada Java


Gambar primitif merupakan gambar bentuk-bentuk dasar seperti lingkaran, persegi, segitiga, poligon, dll. Namun pada postingan kali ini telah dilengkapi dengan warna, langsung aja berikut source code nya :

import java.awt.Color;
import java.awt.Graphics;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
public class Mardin extends javax.swing.JFrame {
public Mardin() {
initComponents();
}
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new Mardin().setVisible(true);
}
});
}
@SuppressWarnings(“unchecked”)
class garis extends JPanel {
public void paintComponent(Graphics garis) {
super.paintComponent(garis);
garis.setColor(Color.DARK_GRAY);
garis.drawLine(10, 100, 150, 100);
}
}
class titik extends JPanel {
public void paintComponent(Graphics g) {
super.paintComponent(g);
g.setColor(Color.RED);
g.drawLine(80, 90, 81, 90);
}
}
class segiempat extends JPanel {
public void paintComponent(Graphics g) {
super.paintComponent(g);
g.setColor(Color.green);
g.fillRect(30, 50, 100, 100);
}
}
class segitiga extends JPanel {
public void paintComponent(Graphics g) {
super.paintComponent(g);
g.setColor(Color.red);
int[] x = {20, 80, 140};
int[] y = {150, 40, 150};
g.fillPolygon(x, y, 3);
}
}
class bulat extends JPanel {
public void paintComponent(Graphics g) {
super.paintComponent(g);
g.setColor(Color.blue);
g.fillOval(30, 45, 105, 105);
}
}
class polygon extends JPanel {
public void paintComponent(Graphics a) {
super.paintComponent(a);
int[] x = {25, 55, 115, 145, 115, 55};
int[] y = {57, 7, 7, 57, 107, 107};
a.setColor(Color.ORANGE);
a.fillPolygon(x, y, 6);
}
}

Untuk melihat kode lengkapnya klik disini

Hasilnya adalah sebagai berikut:
lingkaran garis

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s