Pages

Subscribe:

Ads 468x60px

♪ ♥ Get Paid Daily - The Best Sites PTC ♥ ♪
DonkeyMails.com: No Minimum Payout
AyuWage Services - Get Paid to Visits Sites and Complete Surveys

Minggu, 23 September 2012

Progrman Animasi BallRoom Dengan Java

Jumpa lagi di Imposible Sin Vosotras, kali ini yang mungki ane postingin yaitu tentang membuat animasi sederhana menggunakan bahasa pemrograman java. Dalam animasi ini, saya pake aplikasi JCreator.
Berikut listing programnya :


simapan dengan BallRoom.java


import java.awt.*;
import java.awt.event.*;
import java.awt.geom.*;
import java.util.*;
import javax.swing.*;

public class BallRoom extends JFrame {

public static void main(String[] args)
{
new BallRoom(); //MENJALANKAN KONSTRUKTOR BALLROOM
}

public BallRoom() {
this.setSize(500, 500); // MEMBUAT WINDOW
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.add(new PaintSurface(), BorderLayout.CENTER);
Thread t = new AnimationThread(this); // MENJALANKAN THREAD TERHADAP VARIABLE T
t.start();
this.show();
}

}

class AnimationThread extends Thread {
JFrame c;

public AnimationThread(JFrame c){
this.c = c;
}

public void run(){
while(true){
c.repaint(); // MENGHAPUS GAMBAR SETELAH BERPUTAR
try{
Thread.sleep(30); // FRAME GAMBAR PERDETIK
}
catch(InterruptedException ex){
}
}

}
}
class PaintSurface extends JComponent{
double x_pos = 100;
double y_pos = 100;
int rotation = 0;
double angle = 0;

public void paint(Graphics g){
Graphics2D g2 = (Graphics2D)g; // MEMBERI VARIABLE G PADA GRAPHIC KE G2
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
if(rotation == 360) {
rotation = 0;
}
else {
rotation += 20; // PERTTAMBAHAN PERCEPATAN ROTASI
angle -= 0.05;
x_pos = 100*Math.cos(angle)+150; // MEREVOLUSI OBYEK
y_pos = 100*Math.sin(angle)+150;
}

Shape ball = new Ellipse2D.Float((int)x_pos,(int)y_pos, 50, 20); // FUNGSI MEMBENTUK ELIPS
g2.rotate(Math.toRadians(rotation), x_pos + 50/2, y_pos + 20/2); // METOTASI OBYEK
g2.setColor(Color.RED); // MEMBERI WARNA OBYEK
g2.fill(ball); // MENGAMBAR
}
}
Hasilnya Seperti Berikut :


Artikel Terkait :


0 komentar:

Posting Komentar

Please Give Your Feedback Or Message.
Thank You!!?

Unique 1:1 Traffic Exchange

♪ ♥ Ma liste de blogs ♥ ♪

♪ ♥ Please Votes! Thanks. ♪ ♥
×