Pada postingan ini saya ingin membagi sedikit tentang bahasa Java yaitu membuat gambar orang. Sempet binggung juga sih, tapi akhirnya bisa juga, Penampakannya seperti di bawah ini:
Hasil gambar orang di Java. |
Langsung saja seperti biasa jalankan netbeans agan pilih file/New Project/Java/Java Application. Lalu klik next. Untuk project name nya terserahAgan2 saja kemudian klik finish. Pada class Main.java copy paste script dibawah ini :
Class main
package javaapplication36;
public class Main {
public static void main(String[] args) {
javax.swing.JFrame frame = new javax.swing.JFrame();
frame.setSize (420,400);
frame.setDefaultCloseOperation(javax.swing.JFrame.EXIT_ON_CLOSE);
frame.getContentPane().add (new gambar ());
frame.setVisible(true);
}
}
public class Main {
public static void main(String[] args) {
javax.swing.JFrame frame = new javax.swing.JFrame();
frame.setSize (420,400);
frame.setDefaultCloseOperation(javax.swing.JFrame.EXIT_ON_CLOSE);
frame.getContentPane().add (new gambar ());
frame.setVisible(true);
}
}
Kemudian buat class baru di packege yg anda buat td, isi nama classnya dengan "gambar.java". dan copy script di bawah ini :
Class gambar
package javaapplication36;
import java.awt.geom.*;
import java.awt.Color;
import java.awt.BasicStroke;
import java.awt.*;
import java.applet.*;
public class gambar extends javax.swing.JComponent {
@Override
public void paint (java.awt.Graphics g){
java.awt.Graphics2D g2 = (java.awt.Graphics2D)g;
g2.drawOval(120, 60, 90, 90);//kepala
g2.setColor(Color.black);
g2.fillOval(140,90, 10, 10);
g.drawOval(140, 90, 10, 10);//mata kiri
g2.setColor(Color.black);
g2.fillOval(180,90, 10, 10);
g.drawOval(180, 90, 10, 10);//mata kanan
g2.draw(new Arc2D.Double(135, 80, 60, 60, 180, 180, Arc2D.OPEN));//mulut
g2.setColor(Color.BLACK);
g2.drawLine(60, 250, 90, 250);//tangan kiri
g2.drawLine(260, 250, 230, 250);//tangan kanan
g2.drawArc(60, 150, 200, 200, 0, 180);
g2.draw(new Arc2D.Double(72, 200, 70, 750, 60, 60, Arc2D.OPEN));
g2.draw(new Arc2D.Double(178, 200, 70, 750, 60, 60, Arc2D.OPEN));
g2.drawLine(124,250,124,350);
g2.drawLine(196,250,196,350);
g2.draw(new Arc2D.Double(125, 300, 70, 750, 60, 60, Arc2D.OPEN));
g2.drawLine(178, 350, 195, 350);
g2.drawLine(143, 350, 123, 350);
//tulisan
g2.setFont(new Font("Arial", Font.PLAIN, 21));
g2.setColor(Color.BLACK);
g2.drawString("Gambar Orang", 120, 20);
g2.drawString("(Dengan Scale & Translate) di Java", 20, 40);
//translate & scacle
g2.scale(0.5, 0.5);
g2.translate(450,350);
g2.setColor(Color.gray);
g2.setColor(Color.black);
g2.fillOval(140,90, 10, 10);
g2.fillOval(180,90, 10, 10);
g.drawOval(120, 60, 90, 90);//kepala
g.drawOval(140, 90, 10, 10);//mata kiri
g.drawOval(180, 90, 10, 10);//mata kanan
g2.draw(new Arc2D.Double(135, 80, 60, 60, 180, 180, Arc2D.OPEN));//mulut
g2.drawLine(60, 250, 90, 250);//tangan kiri
g2.drawLine(260, 250, 230, 250);//tangan kanan
g2.drawArc(60, 150, 200, 200, 0, 180);
g2.draw(new Arc2D.Double(72, 200, 70, 750, 60, 60, Arc2D.OPEN));
g2.draw(new Arc2D.Double(178, 200, 70, 750, 60, 60, Arc2D.OPEN));
g2.drawLine(124,250,124,350);
g2.drawLine(196,250,196,350);
g2.draw(new Arc2D.Double(125, 300, 70, 750, 60, 60, Arc2D.OPEN));
g2.drawLine(178, 350, 195, 350);
g2.drawLine(143, 350, 123, 350);
}
}
import java.awt.geom.*;
import java.awt.Color;
import java.awt.BasicStroke;
import java.awt.*;
import java.applet.*;
public class gambar extends javax.swing.JComponent {
@Override
public void paint (java.awt.Graphics g){
java.awt.Graphics2D g2 = (java.awt.Graphics2D)g;
g2.drawOval(120, 60, 90, 90);//kepala
g2.setColor(Color.black);
g2.fillOval(140,90, 10, 10);
g.drawOval(140, 90, 10, 10);//mata kiri
g2.setColor(Color.black);
g2.fillOval(180,90, 10, 10);
g.drawOval(180, 90, 10, 10);//mata kanan
g2.draw(new Arc2D.Double(135, 80, 60, 60, 180, 180, Arc2D.OPEN));//mulut
g2.setColor(Color.BLACK);
g2.drawLine(60, 250, 90, 250);//tangan kiri
g2.drawLine(260, 250, 230, 250);//tangan kanan
g2.drawArc(60, 150, 200, 200, 0, 180);
g2.draw(new Arc2D.Double(72, 200, 70, 750, 60, 60, Arc2D.OPEN));
g2.draw(new Arc2D.Double(178, 200, 70, 750, 60, 60, Arc2D.OPEN));
g2.drawLine(124,250,124,350);
g2.drawLine(196,250,196,350);
g2.draw(new Arc2D.Double(125, 300, 70, 750, 60, 60, Arc2D.OPEN));
g2.drawLine(178, 350, 195, 350);
g2.drawLine(143, 350, 123, 350);
//tulisan
g2.setFont(new Font("Arial", Font.PLAIN, 21));
g2.setColor(Color.BLACK);
g2.drawString("Gambar Orang", 120, 20);
g2.drawString("(Dengan Scale & Translate) di Java", 20, 40);
//translate & scacle
g2.scale(0.5, 0.5);
g2.translate(450,350);
g2.setColor(Color.gray);
g2.setColor(Color.black);
g2.fillOval(140,90, 10, 10);
g2.fillOval(180,90, 10, 10);
g.drawOval(120, 60, 90, 90);//kepala
g.drawOval(140, 90, 10, 10);//mata kiri
g.drawOval(180, 90, 10, 10);//mata kanan
g2.draw(new Arc2D.Double(135, 80, 60, 60, 180, 180, Arc2D.OPEN));//mulut
g2.drawLine(60, 250, 90, 250);//tangan kiri
g2.drawLine(260, 250, 230, 250);//tangan kanan
g2.drawArc(60, 150, 200, 200, 0, 180);
g2.draw(new Arc2D.Double(72, 200, 70, 750, 60, 60, Arc2D.OPEN));
g2.draw(new Arc2D.Double(178, 200, 70, 750, 60, 60, Arc2D.OPEN));
g2.drawLine(124,250,124,350);
g2.drawLine(196,250,196,350);
g2.draw(new Arc2D.Double(125, 300, 70, 750, 60, 60, Arc2D.OPEN));
g2.drawLine(178, 350, 195, 350);
g2.drawLine(143, 350, 123, 350);
}
}
Oke sekian dulu dari saya, semoga bermanfaat. Dan selamat Mencoba!!!