UAS GRAFIKA KOMPUTER - Mmembuat Animasi Sederhana menggunakan Netbeans

Kali ini saya akan membagikan sebuah program animasi sederhana menggunakan java Netbeans, dimana pada hasil Program akan menampilkan Animasi Huruf. . .
 Langsung Saja  saya Tampilkan codingnya :

package javaapplication9.uas;



import java.awt.*;
import java.awt.event.*;
public class animasiSederhana extends Frame implements Runnable {
Thread animation;
// Mengatur waktu delay
int frameDelay = 350;
// Objek yang akan ditampilkan
String frames[] = {"COSMAS_INTAN_KELEN","13110259","STIKOM_ARTHA_BUANA-KUPANG","##","##","##","IAN","IAN","IAN"};
// Menentukan variabel yang diperlukan
int numFrames = frames.length;
int currentFrame = 50;
long lastDisplay = 50;
int screenWidth = 500; //lebar layar
int screenHeight = 200; //tinggi layar
public static void main(String args[]) {
animasiSederhana app = new animasiSederhana();
}
public animasiSederhana() {
super("Animasi Sederhana");
setup();
setSize(screenWidth,screenHeight);
addWindowListener(new WindowEventHandler());
show();
animation = new Thread(this);
animation.start();
}
void setup() {
setupMenuBar();
setFont(new Font("default",Font.BOLD,18)); //mengatur font
}
void setupMenuBar() {
MenuBar menuBar = new MenuBar();
Menu fileMenu = new Menu("File");
MenuItem fileExit = new MenuItem("Tutup");
fileExit.addActionListener(new MenuItemHandler());
fileMenu.add(fileExit);
menuBar.add(fileMenu);
setMenuBar(menuBar);
}
public void paint(Graphics g) {
g.drawString(frames[currentFrame],90,90); //membuat frame
}
public void run() {
// membuat animasi (perulangan)
do {
long time = System.currentTimeMillis();
if(time - lastDisplay > frameDelay) {
repaint();
try {
Thread.sleep(frameDelay); //berhenti selama frameDelay=100
}catch(InterruptedException ex){
}
++currentFrame;
currentFrame %= numFrames;
lastDisplay = time;
}
} while (true);
}
class MenuItemHandler implements ActionListener, ItemListener {
public void actionPerformed(ActionEvent ev){
String s=ev.getActionCommand();
if(s=="Exit"){
System.exit(0);
}
}
public void itemStateChanged(ItemEvent e){
}
}
//Kelas yang digunakan agar tombol close pada frame bisa berfungsi
class WindowEventHandler extends WindowAdapter {
public void windowClosing(WindowEvent e){
System.exit(0);
}
}
}


Oke,baik setelah itu kira-kira akan muncul hasilnya Sebagai berikut :

Komentar

Postingan Populer