Sambil jaga warnet gak ada kerjaan, mau online mulu bosen, jadi saya coba coding-codingan menggunakan java, dan kebetulan saya lagi mendalami game berbasis java untuk TA(Skripsi) saya, mohon doanya ya temen2.. smoga TA saya selesai 100% dan saya lulus, kmudian menjadi dosen bahasa pemrograman JAVA. Amiinn....
inilah hasil codingan saya sambil ku' kengku' (madura).
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.Toolkit;
import javax.swing.JFrame;
/**
*
* @author UDIN
*/
public class TimerThread extends JFrame implements Runnable{
Thread th;
boolean running;
int i;
long detik;
int menit;
int jam;
Image start;
public TimerThread(){
running=true;
th=new Thread(this);
setTitle("Timer Thread");
setSize(200, 100);
int w=Toolkit.getDefaultToolkit().getScreenSize().width;
int h=Toolkit.getDefaultToolkit().getScreenSize().height;
setLocation(w/2-this.getWidth()/2, h/2-this.getHeight()/2);
setVisible(true);
}
public void paint(Graphics g){
g.clearRect(0, 0,500, 500);
g.setColor(Color.blue);
Font f=new Font("Times new Roman", 1,20);
g.setFont(f);
g.drawString("Time : "+jam+":"+menit+":"+detik, 20,70);
}
public void run() {
while(running){
try{
Thread.sleep(20);
}catch(Exception e){}
if(i==60){
detik=detik+1;
i=1;
}
if(detik==60){
menit=menit+1;
detik=1;
}
if(menit==60){
jam=jam+1;
menit=1;
}
i++;
repaint();
}
}
}
dan jika dikompile maka hasilnya seperti berikut
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.Toolkit;
import javax.swing.JFrame;
/**
*
* @author UDIN
*/
public class TimerThread extends JFrame implements Runnable{
Thread th;
boolean running;
int i;
long detik;
int menit;
int jam;
Image start;
public TimerThread(){
running=true;
th=new Thread(this);
setTitle("Timer Thread");
setSize(200, 100);
int w=Toolkit.getDefaultToolkit().getScreenSize().width;
int h=Toolkit.getDefaultToolkit().getScreenSize().height;
setLocation(w/2-this.getWidth()/2, h/2-this.getHeight()/2);
setVisible(true);
}
public void paint(Graphics g){
g.clearRect(0, 0,500, 500);
g.setColor(Color.blue);
Font f=new Font("Times new Roman", 1,20);
g.setFont(f);
g.drawString("Time : "+jam+":"+menit+":"+detik, 20,70);
}
public void run() {
while(running){
try{
Thread.sleep(20);
}catch(Exception e){}
if(i==60){
detik=detik+1;
i=1;
}
if(detik==60){
menit=menit+1;
detik=1;
}
if(menit==60){
jam=jam+1;
menit=1;
}
i++;
repaint();
}
}
}
dan jika dikompile maka hasilnya seperti berikut