This code is to indicate system time on your application.This code is depending on your system time while startup the application and then it do feather calculations and counting to maintain accurate time.
This time function can simply embed to a jlabel.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package default; | |
import java.awt.event.ActionEvent; | |
import java.awt.event.ActionListener; | |
import java.text.DateFormat; | |
import java.text.SimpleDateFormat; | |
import java.util.Date; | |
import javax.swing.Timer; | |
/** | |
* | |
* @author Open source developers | |
* Create a instance from this class and pass the jlabel which you desire to hold clock as a parameter to the constructor. | |
*/ | |
public class Showclock { | |
public Showclock(final javax.swing.JLabel jlabel) { | |
final DateFormat timeFormat = new SimpleDateFormat("hh:mm:ss a "); | |
ActionListener timerListener = new ActionListener() | |
{ | |
@Override | |
public void actionPerformed(ActionEvent e) | |
{ | |
Date date = new Date(); | |
jlabel.setText(timeFormat.format(date)); | |
} | |
}; | |
Timer timer = new Timer(1000, timerListener); | |
timer.setInitialDelay(0); | |
timer.start(); | |
} | |
} | |
//////////////// ENJOY JAVA SHARE JAVA ///////////////////////////////// |
0 comments:
Post a Comment
Leave your comment and feedback here for me