WIMPAX BOX 2D
Source code :
import java.applet.Applet;
import java.applet.AudioClip;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.awt.font.*;
import java.awt.geom.*;
import sun.applet.AppletAudioClip;
public class Wimpexbox_2D extends JApplet {
public static void main(String s[]) {
JFrame frame = new JFrame();
frame.setTitle("Wimpex Box");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JApplet applet = new Wimpexbox_2D();
applet.init();
frame.getContentPane().add(applet);
frame.pack();
frame.setVisible(true);
AudioClip s1 = new AppletAudioClip(ClassLoader.getSystemResource("sound/T-U.wav"));
s1.play();
}
public void init() {
JPanel panel = new Panel_wimpex_box3();
getContentPane().add(panel);
}
}
class Panel_wimpex_box3 extends JPanel implements Runnable {
//animasi1
int x1 = 0;
int x2 = 0;
int y1 = 0;
int y2 = 0;
//animasi 2
int start = 1000, posisi = 1000, mundur = 1000;
Thread t = new Thread(this);
public Panel_wimpex_box3() {
setPreferredSize(new Dimension(1350, 690));
t.start();
}
public void paintComponent(Graphics g) {
super.paintComponent(g);
Graphics2D g_1 = (Graphics2D) g;
Graphics2D g2 = (Graphics2D) g;
Graphics2D g3 = (Graphics2D) g;
//Latar
GradientPaint warnaGradien = new GradientPaint(400, 0, Color.yellow, 400, 250, Color.white, false);
Rectangle2D.Double kotak = new Rectangle2D.Double(0, 0, 1350, 690);
g2.setPaint(warnaGradien);
g2.fill(kotak);
g2.setStroke(new BasicStroke(4.0f));
g2.draw(kotak);
// matahari
Ellipse2D.Double matahari = new Ellipse2D.Double(mundur + 210, 10, 100, 100);
g_1.fill(matahari);
g_1.setStroke(new BasicStroke(1.0f));
g_1.setColor(Color.orange);
g_1.fill(matahari);
// awan pertama
GeneralPath gp1 = new GeneralPath();
gp1.moveTo(x1 + 50, 70);
gp1.curveTo(x1 + 50, 70, x1 + 95, 48, x1 + 100, 75);
gp1.curveTo(x1 + 100, 70, x1 + 155, 48, x1 + 160, 75);
gp1.curveTo(x1 + 160, 70, x1 + 225, 50, x1 + 225, 100);
gp1.curveTo(x1 + 235, 80, x1 + 295, 140, x1 + 220, 150);
gp1.curveTo(x1 + 220, 140, x1 + 190, 170, x1 + 170, 140);
gp1.curveTo(x1 + 170, 140, x1 + 145, 170, x1 + 115, 130);
gp1.curveTo(x1 + 115, 130, x1 + 95, 170, x1 + 75, 130);
gp1.curveTo(x1 + 45, 160, x1 + 2, 110, x1 + 45, 70);
g_1.setColor(Color.white);
g_1.fill(gp1);
g_1.setColor(Color.white);
g_1.draw(gp1);
// awan kedua
GeneralPath gp2 = new GeneralPath();
gp2.moveTo(x1 + 290, 20);
gp2.curveTo(x1 + 290, 20, x1 + 335, -2, x1 + 345, 25);
gp2.curveTo(x1 + 345, 20, x1 + 395, -2, x1 + 405, 25);
gp2.curveTo(x1 + 405, 20, x1 + 465, 0, x1 + 470, 50);
gp2.curveTo(x1 + 480, 30, x1 + 535, 90, x1 + 465, 100);
gp2.curveTo(x1 + 465, 90, x1 + 430, 120, x1 + 425, 90);
gp2.curveTo(x1 + 415, 90, x1 + 385, 120, x1 + 360, 80);
gp2.curveTo(x1 + 360, 80, x1 + 335, 120, x1 + 320, 80);
gp2.curveTo(x1 + 290, 110, x1 + 242, 60, x1 + 290, 20);
g_1.setColor(Color.white);
g_1.fill(gp2);
g_1.setColor(Color.white);
g_1.draw(gp2);
// awan ketiga
GeneralPath gp3 = new GeneralPath();
gp3.moveTo(x1 + 550, 50);
gp3.curveTo(x1 + 550, 50, x1 + 595, 28, x1 + 600, 55);
gp3.curveTo(x1 + 600, 50, x1 + 655, 28, x1 + 660, 55);
gp3.curveTo(x1 + 660, 50, x1 + 725, 30, x1 + 725, 80);
gp3.curveTo(x1 + 735, 60, x1 + 795, 120, x1 + 720, 130);
gp3.curveTo(x1 + 720, 120, x1 + 690, 150, x1 + 670, 120);
gp3.curveTo(x1 + 670, 120, x1 + 645, 150, x1 + 615, 110);
gp3.curveTo(x1 + 615, 110, x1 + 595, 150, x1 + 575, 110);
gp3.curveTo(x1 + 545, 140, x1 + 502, 90, x1 + 545, 50);
g_1.setColor(Color.white);
g_1.fill(gp3);
g_1.setColor(Color.white);
g_1.draw(gp3);
// awan kempat
GeneralPath gp4 = new GeneralPath();
gp4.moveTo(x1 + 800, 50);
gp4.curveTo(x1 + 800, 50, x1 + 845, 28, x1 + 855, 55);
gp4.curveTo(x1 + 855, 50, x1 + 905, 28, x1 + 915, 55);
gp4.curveTo(x1 + 915, 50, x1 + 975, 30, x1 + 980, 80);
gp4.curveTo(x1 + 990, 60, x1 + 1045, 120, x1 + 975, 130);
gp4.curveTo(x1 + 975, 120, x1 + 940, 150, x1 + 925, 120);
gp4.curveTo(x1 + 925, 120, x1 + 895, 150, x1 + 870, 110);
gp4.curveTo(x1 + 870, 110, x1 + 845, 150, x1 + 830, 110);
gp4.curveTo(x1 + 800, 140, x1 + 752, 90, x1 + 800, 50);
g_1.setColor(Color.white);
g_1.fill(gp4);
g_1.setColor(Color.white);
g_1.draw(gp2);
//trotoar
Rectangle2D.Double persegipanjang = new Rectangle2D.Double(0, 475, 1350, 100);
g2.setColor(new Color(153, 153, 153));
g2.fill(persegipanjang);
g2.setColor(Color.black);
g2.setStroke(new BasicStroke(2.0f));
g2.draw(persegipanjang);
g2.drawLine(1375, 475, 1300, 550);
g2.drawLine(1275, 475, 1200, 550);
g2.drawLine(1175, 475, 1100, 550);
g2.drawLine(1075, 475, 1000, 550);
g2.drawLine(975, 475, 900, 550);
g2.drawLine(875, 475, 800, 550);
g2.drawLine(775, 475, 700, 550);
g2.drawLine(675, 475, 600, 550);
g2.drawLine(575, 475, 500, 550);
g2.drawLine(475, 475, 400, 550);
g2.drawLine(375, 475, 300, 550);
g2.drawLine(275, 475, 200, 550);
g2.drawLine(175, 475, 100, 550);
g2.drawLine(75, 475, 0, 550);
Rectangle2D.Double persegi = new Rectangle2D.Double(0, 550, 1350, 25);
g2.setColor(Color.GRAY);
g2.fill(persegi);
g2.setColor(Color.black);
g2.setStroke(new BasicStroke(2.0f));
g2.draw(persegi);
g2.drawLine(100, 550, 100, 575);
g2.drawLine(200, 550, 200, 575);
g2.drawLine(300, 550, 300, 575);
g2.drawLine(400, 550, 400, 575);
g2.drawLine(500, 550, 500, 575);
g2.drawLine(600, 550, 600, 575);
g2.drawLine(700, 550, 700, 575);
g2.drawLine(800, 550, 800, 575);
g2.drawLine(900, 550, 900, 575);
g2.drawLine(1000, 550, 1000, 575);
g2.drawLine(1100, 550, 1100, 575);
g2.drawLine(1200, 550, 1200, 575);
g2.drawLine(1300, 550, 1300, 575);
g2.drawLine(1400, 550, 1400, 575);
// menggambar wimpexBox
Graphics2D g_4 = (Graphics2D) g;
// Kepala
Rectangle2D.Double warna = new Rectangle2D.Double(mundur + 750, 200, 190, 100);
g2.setColor(Color.orange);
g2.fill(warna);
g2.setColor(Color.black);
g2.draw(warna);
g_4.draw(new Rectangle2D.Double(mundur + 750, 200, 190, 100));
// Badan
Rectangle2D.Double warna1 = new Rectangle2D.Double(mundur + 800, 302, 90, 150);
g2.setColor(Color.orange);
g2.fill(warna1);
g2.setColor(Color.black);
g2.draw(warna1);
g_4.draw(new Rectangle2D.Double(mundur + 800, 302, 90, 150));
// Tangan Kanan
Rectangle2D.Double warna2 = new Rectangle2D.Double(mundur + 765, 309, 30, 120);
g2.setColor(Color.orange);
g2.fill(warna2);
g2.setColor(Color.black);
g2.draw(warna2);
g_4.draw(new Rectangle2D.Double(mundur + 765, 309, 30, 120));
// Tangan kiri
Rectangle2D.Double warna3 = new Rectangle2D.Double(mundur + 895, 309, 30, 120);
g2.setColor(Color.orange);
g2.fill(warna3);
g2.setColor(Color.black);
g2.draw(warna3);
g_4.draw(new Rectangle2D.Double(mundur + 895, 309, 30, 120));
// Kaki Kanan
Rectangle2D.Double warna4 = new Rectangle2D.Double(mundur + 810, 453, 30, 70);
g2.setColor(Color.orange);
g2.fill(warna4);
g2.setColor(Color.black);
g2.draw(warna4);
g_4.draw(new Rectangle2D.Double(mundur + 810, 453, 30, 70));
// Kaki Kiri
Rectangle2D.Double warna5 = new Rectangle2D.Double(mundur + 852, 453, 30, 70);
g2.setColor(Color.orange);
g2.fill(warna5);
g2.setColor(Color.black);
g_4.draw(new Rectangle2D.Double(mundur + 852, 453, 30, 70));
// mata kanan
g_1.setColor(Color.black);
g_1.fill(new Ellipse2D.Double(mundur + 800, 225, 20, 20));
// mata kiri
g_1.setColor(Color.black);
g_1.fill(new Ellipse2D.Double(mundur + 865, 225, 20, 20));
// hidung
GeneralPath gp5 = new GeneralPath();
gp5.moveTo(mundur + 843, 245);
gp5.lineTo(mundur + 829, 269);
gp5.lineTo(mundur + 857, 269);
gp5.lineTo(mundur + 843, 245);
g_1.setColor(Color.black);
g_1.fill(gp5);
//jalan
Rectangle2D.Double persegi2 = new Rectangle2D.Double(0, 575, 1350, 125);
g2.setColor(Color.black);
g2.fill(persegi2);
g2.setColor(Color.black);
g2.setStroke(new BasicStroke(2.0f));
g2.draw(persegi2);
float[] dashPattern;
float dashPhase = 2.0f;
dashPattern = new float[2];
dashPattern[0] = 100;
dashPattern[1] = 25;
g2.setColor(Color.white);
BasicStroke bsDashed = new BasicStroke(7.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 2.0f, dashPattern, dashPhase);
g2.setStroke(bsDashed);
g2.drawLine(0, 635, 1350, 635);
}
public void run() {
while (true) {
if (posisi == start) {
mundur -= 1;
if (mundur <= -500) {
mundur = posisi;
}
}
if (x1 < 400 && y1 == 0) {
x1++;
}
if (y1 < 300 && x1 == 399) {
y1++;
}
if (x1 < 400 && y1 == 299) {
x1--;
}
if (y1 < 300 && x1 == 0) {
y1--;
}
if (x2 < 400 && y2 == 0) {
x2++;
}
if (y2 < 300 && x2 == 399) {
y2++;
}
if (x2 < 400 && y2 == 299) {
x2--;
}
if (y2 < 300 && x2 == 0) {
y2--;
}
try {
Thread.sleep(18);
} catch (Exception e) {
}
repaint();
}
}
}

Tidak ada komentar:
Posting Komentar