Tutorial Grafika Komputer Menggunakan JAVA 2D ( ANIMASI 6 )


Kali ini kami akan mencoba menjelaskan tentang bagaimana cara untuk membuat Animasi menggunakan Java Netbeen. Tak usah banyak basa basi lagi mari ikuti Langkah - langkah berikut :
1. Yang pertama perlu kita lakukan adalah kita buat file.java
2. Lalu kita isikan dengan scriptnya, sebagai berikut :
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package uasgrafkom;

/**
 *
 * @author AlvianLingga
 */
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.awt.geom.Line2D.Double;
import java.awt.geom.Rectangle2D;

/**
 *
 * @author AlvianLingga
 */
public class Uasgrafkom extends Frame implements Runnable{
   Thread Animasi;
   int Delay = 80;
   int Range = 2700;
   int Awal = 0;
   int Akhir = 0;

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        Uasgrafkom App = new Uasgrafkom();
    }
   
    public Uasgrafkom(){
        setTitle("lingga");
        Author();
        setSize(1300, 700);
        setBackground (new Color(128,255,255));
        setLocation(230, 0);
        addWindowListener(new WindowEventHandler());
        show();
        Animasi = new Thread(this);
        Animasi.start();
    }

   
    void Author(){
        setFont(new Font("Comic Sans MS",Font.BOLD,12));
        setForeground(Color.BLUE);
    }
   
    public void paint(Graphics g){
       
       
        g.drawString("Create By: LINGGA", 10, 1000);
       
     

        //matahari
        g.setColor(Color.YELLOW);
        g.fillOval(500, 50, 100, 100);
      
        //AWAN satu
        g.setColor(Color.white);
        g.fillOval(-1210-Awal, 50, 85, 55);
        g.fillOval(-1160-Awal, 50, 100, 45);
        g.fillOval(-1230-Awal, 50, 150, 75);
        //Awan 2
        g.setColor(Color.white);
        g.fillOval(-920-Awal, 50, 205, 55);
        g.fillOval(-960-Awal, 50, 100, 45);
        g.fillOval(-930-Awal, 50, 150, 75);
        //awan banyak
        g.setColor(Color.white);
        g.fillOval(-1310-Awal, 50, 115, 45);
        g.fillOval(-1060-Awal, 50, 130, 75);
        g.fillOval(-930-Awal, 50, 180, 75);
        g.fillOval(-210-Awal, 50, 105, 55);
        g.fillOval(-160-Awal, 50, 100, 45);
        g.fillOval(-230-Awal, 50, 150, 75);
        g.fillOval(-410-Awal, 50, 85, 55);
        g.fillOval(-360-Awal, 50, 100, 45);
        g.fillOval(-530-Awal, 50, 150, 75);
   
        //belakangputih
        g.setColor(Color.white);
        g.fillArc(1100, 200, 90, 300, 270, 180);
      
        //belakangbawahabu
        g.setColor(new Color(100,100,100));
        int [] a ={1190,1165,1165,1190};
        int [] b ={430,410,350,350};
        g.fillPolygon(a, b, 4);
       
        //belakangabu
        g.setColor(new Color(197,197,197));
        g.fillArc(1100, 200, 70, 280, 270, 180);
       
        //belakangbawah
        g.setColor(Color.white);
        int [] x ={1145,1180,1190,1165,1145};
        int [] y ={500,490,430,410,420};
        g.fillPolygon(x, y, 5);
        g.setColor(Color.black);
        int [] d ={1145,1180,1190,1165,1145};
        int [] c ={500,490,430,410,420};
        g.drawPolygon(d, c, 5);
       
        //badan
        g.setColor(Color.white);
        g.fillRect(150, 200, 1000, 300);
        g.setColor(Color.white);
        int [] z ={1150,950,600,400,200,150};
        int [] n ={500,510,515,510,505,500};
        g.fillPolygon(z, n, 6);
        g.setColor(Color.black);
        int [] m={140,150,150,150,380,380,200,150};
        int [] h={370,220,210,200,200,210,210,370};
        g.fillPolygon(m,h,8);
        g.fillArc(150,  150, 230, 100, 0, 180);
        g.setColor(new Color(197,197,197));
        int [] o={150,140,140,150,155,160,200,220,380,380,220};
        int [] k={450,440,370,360,330,250,220,205,205,210,215};
        g.fillPolygon(o,k,11);        
        g.fillArc(160, 210, 80, 120, 60, 180);
        g.fillArc(180, 200, 120, 40, 0, 180);
       
        g.setColor(Color.white);
        g.fillRoundRect(550, 180, 250, 40, 40, 40);
       
        //kaca       
        g.setColor(new Color(171,241,240));
        g.fillArc(160, 205, 300, 150, 50, 180);
       
        g.setColor(Color.black);
        g.fillArc(155, 205, 300, 150, 420, 180);
        int [] t={145,140,200,210,230,255,285,310,330};
        int [] nn={305,385,385,385,370,345,320,300,280};
        g.fillPolygon(t,nn,9);
        g.setColor(new Color(171,241,240));
        g.fillArc(155, 220, 300, 150, 420, 180);
        int [] s={155,150,200,210,230};
        int [] v={300,380,380,380,360};
        g.fillPolygon(s,v,5);
        g.setColor(Color.black);
        g.fillRect(250, 210, 900, 80);
       
        g.setColor(new Color(171,241,240));
        g.fillRect(985, 220, 160, 65);
       
        g.setColor(new Color(171,241,240));
        g.fillRect(815, 220, 160, 65);
       
        g.setColor(new Color(171,241,240));
        g.fillRect(645, 220, 160, 65);
       
        g.setColor(new Color(171,241,240));
        g.fillRect(475, 220, 160, 65);
       
        g.setColor(new Color(171,241,240));
        int [] e={465,465,375,325};
        int [] f={285,220,220,285};
        g.fillPolygon(e, f, 4);
       
        g.setColor(new Color(171,241,240));
        int [] p={260,260,365,315};
        int [] l={285,220,220,285};
        g.fillPolygon(p, l, 4);
       
       
       
        //setengah
        g.setColor(Color.black);
        g.fillArc(300, 435, 125, 150, 0, 180);
        g.setColor(Color.black);
        g.fillArc(840, 435, 125, 150, 0, 180);
      
        //bawah depan
        g.setColor(Color.white);
        int [] q={150,135,130,130,140,150};
        int [] w={500,495,480,450,440,450};
        g.fillPolygon(q, w, 6);
       
       
        g.setColor(Color.black);
        int []i={150,150,150,220,220,220,150};
        int []j={500,480,450,450,505,450,450};
        g.drawPolygon(i,j,7);
       
        //jalan
        g.setColor(Color.BLACK);
        g.fillRect(0, 520, 1500, 300);
       
        //oren hitam
        g.setColor(Color.black);
        g.fillRoundRect(168, 478,  35, 20, 500, 500);
        g.setColor(Color.orange);
        g.fillRoundRect(170, 480,  30, 15, 500, 500);
      
        g.setColor(Color.black);
        g.fillRoundRect(353, 398,  25, 15, 500, 500);
        g.setColor(Color.orange);
        g.fillRoundRect(355, 400,  20, 10, 500, 500);
       
        g.setColor(Color.black);
        g.fillRoundRect(493, 448,  25, 15, 10, 10);
        g.setColor(Color.orange);
        g.fillRoundRect(495, 450,  20, 10, 10, 10);
       
        g.setColor(Color.black);
        g.fillRoundRect(618, 448,  25, 15, 10, 10);
        g.setColor(Color.orange);
        g.fillRoundRect(620, 450,  20, 10, 10, 10);
       
        g.setColor(Color.black);
        g.fillRoundRect(748, 448,  25, 15, 10, 10);
        g.setColor(Color.orange);
        g.fillRoundRect(750, 450,  20, 10, 10, 10);

        g.setColor(Color.black);
        g.fillRoundRect(888, 398,  25, 15, 10, 10);
        g.setColor(Color.orange);
        g.fillRoundRect(890, 400,  20, 10, 10, 10);
       
        g.setColor(Color.black);
        g.fillRoundRect(1060, 475,  15, 10, 15, 15);
        g.setColor(Color.orange);
        g.fillRoundRect(1137, 430,  12, 8, 15, 15);
       
        //lubangkipas
        g.setColor(new Color(197,197,197));
        g.fillRoundRect(995, 390,  140, 80, 20, 20);
        g.setColor(Color.black);
        g.drawLine(999, 394, 1131, 394);
        g.drawLine(997, 397, 1133, 397);
        g.drawLine(995, 400, 1135, 400);
        g.drawLine(995, 403, 1135, 403);
        g.drawLine(995, 406, 1135, 406);
        g.drawLine(995, 409, 1135, 409);
        g.drawLine(995, 412, 1135, 412);
        g.drawLine(995, 415, 1135, 415);
        g.drawLine(995, 418, 1135, 418);
        g.drawLine(995, 421, 1135, 421);
        g.drawLine(995, 424, 1135, 424);
        g.drawLine(995, 427, 1135, 427);
        g.drawLine(995, 430, 1135, 430);
        g.drawLine(995, 433, 1135, 433);
        g.drawLine(995, 436, 1135, 436);
        g.drawLine(995, 439, 1135, 439);
        g.drawLine(995, 442, 1135, 442);
        g.drawLine(995, 445, 1135, 445);
        g.drawLine(995, 448, 1135, 448);
        g.drawLine(995, 451, 1135, 451);
        g.drawLine(995, 454, 1135, 454);
        g.drawLine(995, 457, 1135, 457);
        g.drawLine(995, 460, 1135, 460);
        g.drawLine(997, 463, 1133, 463);
        g.drawLine(999, 466, 1131, 466);
       
       
       
        //kecil
        g.setColor(Color.orange);
        g.fillRoundRect(245, 440,  15, 10, 80, 80);
       
       
        //garis
        g.setColor(Color.black);
        g.drawLine(220, 370, 1150, 370);
        g.drawLine(290, 507, 290, 370);
        g.drawLine(220,420,440,420);
        g.drawLine(440,370,440,510);
        g.drawLine(565,370,565,515);
        g.drawLine(690,370,690,515);
        g.drawLine(820,370,820,510);
        g.drawLine(820,420,980,420);
        g.drawLine(980,370,980,420);
        g.drawLine(990,370,990,505);
        //garis jalan
            g.setColor(Color.white);
        g.fillRect(1200-Awal, 600, 100, 20);
        g.fillRect(900-Awal, 600, 100, 20);
        g.fillRect(600-Awal, 600, 100, 20);
        g.fillRect(300-Awal, 600, 100, 20);
        g.fillRect(0-Awal, 600, 100, 20);
        g.fillRect(-300-Awal, 600, 100, 20);
        g.fillRect(-600-Awal, 600, 100, 20);
        g.fillRect(-900-Awal, 600, 100, 20);
        g.fillRect(-1200-Awal, 600, 100, 20);
        g.fillRect(-1500-Awal, 600, 100, 20);
        g.fillRect(-1800-Awal, 600, 100, 20);
        g.fillRect(-2100-Awal, 600, 100, 20);
        g.fillRect(-2400-Awal, 600, 100, 20);
       
        //roda
        g.setColor(new Color(197,197,197));
        g.fillOval(305, 450, 110, 110);
        g.fillOval(850, 450, 110, 110);
       
        g.setColor(new Color(92,63,65));
        g.fillOval(320, 465, 80, 80);
        g.fillOval(865, 465, 80, 80);
       
    
       

    }

    //delay
   
    public void run(){
        do{
            long time = System.currentTimeMillis();
            if(time-Akhir>Delay){
                repaint();
                try{
                    Thread.sleep(Delay);
                }catch(InterruptedException ex){
                }
                Awal = Awal-10;
                Awal%=Range;
                Akhir=(int) time;
            }
        }while(true);
    }
    class WindowEventHandler extends WindowAdapter{
        public void windowClosing(WindowEvent e){
            System.exit(0);
        }
    }
  
   
}

3. Run project F6

Semoga tutorial yang kami bagi ini dapat membantu sobat sekalian.
SELAMAT BELAJAR


0 Response to "Tutorial Grafika Komputer Menggunakan JAVA 2D ( ANIMASI 6 ) "

Post a Comment