How To Create Timer with Thread (Basic game Java)

Hiiii all, below is the sourcecode of TimerThread.class this class uses to create  timer and timer used when we create a game that needed...

Hiiii all, below is the sourcecode of TimerThread.class
this class uses to create  timer and timer used when we create a game that needed timer
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 Qolila Tech#
*/
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();
}
}
}

 Compile and the result is,,

COMMENTS

Name

android java linux software SQL Query web
false
ltr
item
Source Tutorials: How To Create Timer with Thread (Basic game Java)
How To Create Timer with Thread (Basic game Java)
https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg24JuQhA_RMVI_Q5F8WixJ8m8mvoUCP0rApO9LIuwQJEeXGhFMhrO1sWjWwThy5DbqlSsC1SpNFNIam3mbXPLMQMtvg6Bt8NIvW5DXJYFpuBWxtpYi98Em26AkDr0sYN-0fIHTn1Vtidlt/s1600/untitled.bmp
https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg24JuQhA_RMVI_Q5F8WixJ8m8mvoUCP0rApO9LIuwQJEeXGhFMhrO1sWjWwThy5DbqlSsC1SpNFNIam3mbXPLMQMtvg6Bt8NIvW5DXJYFpuBWxtpYi98Em26AkDr0sYN-0fIHTn1Vtidlt/s72-c/untitled.bmp
Source Tutorials
https://source-tutorials.blogspot.com/2016/08/how-to-create-timer-with-thread-basic.html
https://source-tutorials.blogspot.com/
http://source-tutorials.blogspot.com/
http://source-tutorials.blogspot.com/2016/08/how-to-create-timer-with-thread-basic.html
true
8522096929325759134
UTF-8
Not found any posts VIEW ALL Readmore Reply Cancel reply Delete By Home PAGES POSTS View All RECOMMENDED FOR YOU LABEL ARCHIVE SEARCH ALL POSTS Not found any post match with your request Back Home Sunday Monday Tuesday Wednesday Thursday Friday Saturday Sun Mon Tue Wed Thu Fri Sat January February March April May June July August September October November December Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec just now 1 minute ago $$1$$ minutes ago 1 hour ago $$1$$ hours ago Yesterday $$1$$ days ago $$1$$ weeks ago more than 5 weeks ago Followers Follow THIS CONTENT IS PREMIUM Please share to unlock Copy All Code Select All Code All codes were copied to your clipboard Can not copy the codes / texts, please press [CTRL]+[C] (or CMD+C with Mac) to copy