Source Code Animasi Kapal Laut

6Deskripsi project:

Aplikasi yang akan dibuat adalah membuat gambar kapal laut dengan background langit, awan, dan matahari.  Pengembangan aplikasi yang akan dibuat adalah membuat kapal dan awan bergerak. Kapal laut akan bergerak dari sisi kanan menuju sisi kiri secara terus menerus dan awan yang bergerak berseberangan satu bergerak dari sisi kanan ke sisi kiri, dan satu dari sisi kiri ke sisi kanan.

Happy Codding ^_^ ….

/*

* To change this template, choose Tools | Templates

* and open the template in the editor.

*/

package grafkom;

/**

*

* @author WAHYOE

*/

import java.awt.*;

import java.awt.event.*;

import java.awt.geom.*;

import java.util.logging.Level;

import java.util.logging.Logger;

import javax.swing.*;

public class ProjectGrafkom extends JApplet {

public static void main(String args[]) {

JFrame frame = new JFrame();

frame.setTitle(“Pemandangan Laut”);

frame.setDefaultCloseOperation(frame.EXIT_ON_CLOSE);

JApplet applet = new ProjectGrafkom();

applet.init();

frame.getContentPane().add(applet);

frame.pack();

frame.setVisible(true);

frame.setLocationRelativeTo(null);

}

public void init() {

JPanel panel = new panel();

getContentPane().add(panel);

}

}

class panel extends JPanel implements Runnable{

int x = 0;

int y = 500;

Thread t = new Thread(this);

public panel() {

setPreferredSize(new Dimension(700, 480));

setBackground(Color.white);

t.start();

}

public void paintComponent(Graphics c) {

super.paintComponent(c);

Graphics2D c2 = (Graphics2D) c;

GeneralPath gp1 = new GeneralPath();

GeneralPath gp2 = new GeneralPath();

GradientPaint g3 = new GradientPaint(210, 300, Color.WHITE, 240, 320, Color.GRAY);

GradientPaint g2 = new GradientPaint(220, 310, Color.GRAY, 270, 340, Color.DARK_GRAY);

//langit

GradientPaint biruLangit = new GradientPaint(0, 300, Color.white, 0, 0, Color.cyan);

Rectangle2D.Double langit = new Rectangle2D.Double(0, 0, 800, 500);

c2.draw(langit);

c2.setPaint(biruLangit);

c2.fill(langit);

//Tiang bendera

c2.setColor(Color.BLACK);

c2.drawLine(y+348, 290, y+348, 230);

//Bendera

c2.setColor(Color.red);

Shape r1=new Rectangle2D.Double(y+350, 230, 50, 10);

c2.fill(r1);

c2.setColor(Color.WHITE);

Shape r2=new Rectangle2D.Double(y+350, 240, 50, 10);

c2.fill(r2);

//laut

c2.setColor(Color.BLUE);

Rectangle2D.Double laut=new Rectangle2D.Double(0, 350, 800, 150);

c2.fill(laut);

// matahari

Shape e1 = new Ellipse2D.Double(550, 50, 100, 100);

GradientPaint g1 = new GradientPaint(535, 80, Color.ORANGE, 550, 130, Color.YELLOW);

c2.setPaint(g1);

c2.fill(e1);

//sinar matahari

BasicStroke b1 = new BasicStroke(3.0f);

c2.setStroke(b1);

float[] dashPattren;

float dashPhase = 0.0f;

dashPattren = new float[4];

dashPattren[0] = 6.0f;

dashPattren[1] = 3.0f;

dashPattren[2] = 2.0f;

dashPattren[3] = 8.0f;

BasicStroke bp1 = new BasicStroke(3.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 5.0f, dashPattren, dashPhase);

c2.setStroke(bp1);

c2.drawLine(495, 10, 580, 60);

c2.drawLine(450, 60, 560, 80);

c2.drawLine(430, 140, 570, 120);

c2.drawLine(470, 200, 600, 140);

// awan2

c2.setColor(Color.white);

Shape e6 = new Ellipse2D.Double(x, 75, 60, 30);

c2.fill(e6);

Shape e7 = new Ellipse2D.Double(x+35, 65, 50, 50); // x,y,lengkungan

c2.fill(e7);

Shape e7a = new Ellipse2D.Double(x+15, 65, 50, 50);

c2.fill(e7a);

Shape e7b = new Ellipse2D.Double(x+55, 65, 50, 50);

c2.fill(e7b);

Shape e8 = new Ellipse2D.Double(x+60, 75, 60, 30);

c2.fill(e8);

//awan1

c2.setColor(Color.white);

Shape e9 = new Ellipse2D.Double(y, 20, 60, 30);

c2.fill(e9);

Shape e10 = new Ellipse2D.Double(y+35, 10, 50, 50);

c2.fill(e10);

Shape e10a = new Ellipse2D.Double(y+15, 10, 50, 50);

c2.fill(e10a);

Shape e10b = new Ellipse2D.Double(y+55, 10, 50, 50);

c2.fill(e10b);

Shape e11 = new Ellipse2D.Double(y+60, 20, 60, 30);

c2.fill(e11);

//awan3 menutupi matahari

c2.setColor(Color.white);

Shape e12 = new Ellipse2D.Double(520, 130, 60, 30);// x,y,lengkungan

c2.fill(e12);

Shape e13 = new Ellipse2D.Double(555, 120, 50, 50);

c2.fill(e13);

Shape e13a = new Ellipse2D.Double(535, 120, 50, 50);

c2.fill(e13a);

Shape e13b = new Ellipse2D.Double(575, 120, 50, 50);

c2.fill(e13b);

Shape e14 = new Ellipse2D.Double(580, 130, 60, 30);

c2.fill(e14);

//awan3 menutupi matahari

c2.setColor(Color.white);

Shape e15 = new Ellipse2D.Double(580, 100, 60, 30);// x,y,lengkungan

c2.fill(e15);

Shape e16 = new Ellipse2D.Double(605, 90, 50, 50);

c2.fill(e16);

Shape e16a = new Ellipse2D.Double(595, 90, 50, 50);

c2.fill(e16a);

Shape e16b = new Ellipse2D.Double(635, 90, 50, 50);

c2.fill(e16b);

Shape e17 = new Ellipse2D.Double(640, 100, 60, 30);

c2.fill(e17);

//atap kapal

gp2.moveTo(y+210, 270);

gp2.lineTo(y+240, 260);

gp2.lineTo(y+335, 260);

gp2.lineTo(y+340, 270);

gp2.closePath();

c2.draw(gp2);

c2.setPaint(g3);

c2.fill(gp2);

//Badan Kapal

gp1.moveTo(y+150, 310);

gp1.lineTo(y+190, 360);

gp1.lineTo(y+330, 360);

gp1.lineTo(y+330, 330);

gp1.lineTo(y+350, 330);

gp1.lineTo(y+350, 310);

gp1.closePath();

c2.draw(gp1);

c2.setPaint(g2);

c2.fill(gp1);

//bagian tengah kapal

GradientPaint g4= new GradientPaint(170, 120, Color.LIGHT_GRAY, 10, 190, Color.GRAY,true);

Shape r3= new Rectangle2D.Double(y+180, 290, 170, 25);

c2.setPaint(g4);

c2.fill(r3);

c2.setColor(Color.lightGray);

Shape r4=new Rectangle2D.Double(y+200, 270, 140, 20);

c2.fill(r4);

c2.setColor(Color.WHITE);

Shape r5=new Rectangle2D.Double(y+295, 275, 30, 10);

c2.fill(r5);

Shape r6=new Rectangle2D.Double(y+240,275, 10, 6);

c2.fill(r6);

Shape r7=new Rectangle2D.Double(y+220, 275, 10, 6);

c2.fill(r7);

c2.setColor(Color.red);

Shape r8=new Rectangle2D.Double(y+180, 309, 170, 4);

c2.fill(r8);

//jendela kapal

c2.setColor(Color.black);

Shape e2 = new Ellipse2D.Double(y+190, 320, 15, 15);

Shape e3 = new Ellipse2D.Double(y+230, 320, 15, 15);

Shape e4 = new Ellipse2D.Double(y+270, 320, 15, 15);

Shape e5 = new Ellipse2D.Double(y+310, 320, 15, 15);

c2.fill(e2);

c2.fill(e3);

c2.fill(e4);

c2.fill(e5);

}

public void run() {

while (true) {

if (x <= 700) {

y–;

x++;

}else {

x=0;

y=500;

}

try {

repaint();

Thread.sleep(25);

} catch (Exception e) {

}

}

}

}

Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout / Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout / Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout / Ubah )

Foto Google+

You are commenting using your Google+ account. Logout / Ubah )

Connecting to %s