Java Implementation Countdown source sharing

Source: Internet
Author: User

Import Java.util.Calendar;

Import Java.util.Date;

Import Java.util.Timer;

Import Java.util.TimerTask;


Import Javax.swing.JFrame;

Import Javax.swing.JLabel;

/**

*

* @author Wesley

* @date January 28, 2015

*

*/

public class Countdown {

Private Long longtime;

Private Long currenttime;

Private Long disttime;

Private Long day, hour, minutes, seconds;

Public Countdown () {

Cdown ();

}

public void Cdown () {

Timer timer = new timer ();

JFrame JF = new JFrame ();

final JLabel jl = new JLabel ();

Jf.add (JL);

jf.setvisible (true);

jf.setsize (350, 100);

jf.settitle ("Countdown Software");

jf.setdefaultcloseoperation (jframe.exit_on_close);

Timer.schedule (New TimerTask () {

@Override

public void run () {

Calendar cal = Calendar.getinstance ();

//set a scheduled time

cal.set (2015, 0, 28, 17, 30, 0);//0 representative January, 11 for December

//Returns the number of milliseconds of the calendar element to a specified time.

longtime = Cal.gettimeinmillis ();

//Returns the number of milliseconds represented by this Date object since January 1, 1970 00:00:00 GMT.

currenttime = new Date (). GetTime ();

//distance of time

disttime = longtime-currenttime;

//Get Days

day = ((disttime/1000)/(3600 * 24));

//Get the number of hours

hour = ((disttime/1000)-day * 86400)/3600;

//Get the number of minutes

minutes = ((disttime/1000)-day * 86400-hour * 3600)/60;

//Get the number of seconds

seconds = (disttime/1000)-day * 86400-hour * 3600

-minutes * 60;

jl.settext ("Countdown" + Day + "days" + Hour + "hours:" + minutes

+ "minutes:" + seconds + "seconds");

  }

}, 0, 1000);

}

public static void Main (string[] args) {

New Countdown ();

}

}


Java Implementation Countdown source sharing

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.