Import Java. AWT. *; import Java. AWT. event. *; import Java. util. *; import javax. swing. *; public class clock extends jframe {private dialog; public static void main (string [] ARGs) {clock F = new clock (); F. setdefaclocloseoperation (jframe. exit_on_close); F. setvisible (true);} class mydialog extends dialog implements windowlistener, actionlistener {jlabel label; jpanel Panel1, panel2; jbutton button; Public m Ydialog (frame owner, String title, Boolean modal) {super (owner, title, modal); // todo auto-generated constructor stublabel = new jlabel ("Time! "); Button = new jbutton (" OK "); Panel1 = new jpanel (); panel2 = new jpanel (); panel1.setlayout (New borderlayout ()); panel1.add ("center", label); panel2.add ("center", button); this. add ("center", Panel1); this. add ("South", panel2); this. setsize (200,200); this. setresizable (false); this. addwindowlistener (this); button. addactionlistener (this);} public void windowopened (invalid wevent e) {// todo auto-generated Method Stub} public void windowclosing (invalid wevent e) {// todo auto-generated method stubthis. setvisible (false);} public void windowclosed (incluwevent e) {// todo auto-generated method stub} public void incluwiconified (incluwevent E) {// todo auto-generated method stub} public void windowdeiconified (incluwevent e) {// todo auto-generated method stub} public void windowactivated (incluwevent E) {// todo auto-Ge Nerated method stub} public void windowdeactivated (incluwevent e) {// todo auto-generated method stub} public void actionreceivmed (actionevent e) {// todo auto-generated method stubthis. setvisible (false) ;}} clock () {settitle ("Countdown"); setsize (320,120); dialog = new mydialog (this, "prompt:", true ); clockpanel P = new clockpanel (); add (p);} class clockpanel extends jpanel {private jbutton B; private Boolean oneti Me = true; private jlabel lfen, lmiao, L; private jtextfield TF, TM; clockpanel () {B = new jbutton ("Start countdown "); lfen = new jlabel ("points"); lmiao = new jlabel ("seconds"); L = new jlabel ("00:00"); TF = new jtextfield (3 ); TM = new jtextfield (3); L. setfont (new font ("", Font. bold, 30); L. setforeground (color. red); B. addactionlistener (New actionlistener () {public void actionreceivmed (actionevent arg0) {If (onetime) {If (TF. Gettext (). trim (). equals ("") {TF. settext ("00");} If (TM. gettext (). trim (). equals ("") {TM. settext ("00");} new changelabel (TF. gettext (). trim () + ":" + TM. gettext (). trim ()). start () ;}}); add (TF); add (lfen); add (TM); add (lmiao); // Add second add (B ); add (l);} class changelabel extends thread // run the second-stitch thread {private int minitues; private string sminitues; private int sound; private string ssound; private string labeltime; Public Changelabel (string time) {// todo auto-generated constructor stubonetime = false; this. minitues = integer. parseint (time. substring (0, time. indexof (':'); this. sound = integer. parseint (time. substring (time. indexof (':') + 1);} private long time1; private long time2; Public void run () {time1 = system. currenttimemillis (); While (true) {time2 = system. currenttimemillis (); While (! (Minitues = 0 & Sound = 0) & time2> = time1 + 1000) {time1 = time2; If (sound = 0) {sound = 59; minitues --;} else {sound --;} labeltime = This. gettime (); display () ;}if (minitues = 0 & Sound = 0) {dialog. setvisible (true); onetime = true; break ;}} private string gettime () {If (minitues <10) This. sminitues = "0" + minitues; elsethis. sminitues = "" + minitues; If (sound <10) This. ssound = "0" + sound; elsethis. ssound = "" + sound; return this. sminitues + ":" + this. ssound;} public void display () {/** display countdown */L. settext (this. labeltime );}}}}
______________________________________________
Another
A small JavaScript code with a 60-second countdown
<Table name = agree border = "0" cellpadding = "10" cellspacing = "0" align = center width = "80%">
<Tr align = center>
& Lt; TD width = "50%" align = "right" & gt;
<Form name = register method = post action = reg_shang.asp? Action = Yes>
<Input type = "hidden" name = "action" value = "agree"> <input class = "go-wenbenkuang" type = submit value = "Agree to register" name = submit>
</Form>
</TD>
& Lt; TD width = "50%" align = "Left" & gt;
<Form action = index. asp method = post> <input class = go-wenbenkuang type = submit value = "I disagree"> </form> </TD>
</Tr>
</Table>
<SCRIPT>
Secs = 60; // Number of secs to delay-China-studio
Wait = secs * 100;
Document. Forms. Register. Submit. Disabled = true;
For (I = 1; I <= (wait/100); I ++ ){
Window. setTimeout ("doupdate (" + I + ")", I * 100 );
}
Window. setTimeout ("timer ()", wait );
Function doupdate (Num ){
If (num = (wait/100 )){
Document. Forms. Register. Submit. value = "Agree to register ";
} Else {
WUT = (wait/ 100)-num;
Document. Forms. Register. Submit. value = "Read (" + WUT + ")" before you agree ")";
}
}
Function timer (){
Document. Forms. Register. Submit. Disabled = false;
}
</SCRIPT>
--- Another method that can be directly parsed
<SCRIPT>
<! --
// Obtain the current time. The scale is one thousand minutes/second.
VaR initializationtime = (new date (). gettime ();
Function showlefttime (){
VaR now = new date ();
VaR year = now. getyear ();
VaR month = now. getmonth ();
VaR day = now. getdate ();
VaR hours = now. gethours ();
VaR minutes = now. getminutes ();
VaR seconds = now. getseconds ();
Document. all. show. innerhtml = "Current Time: "+ year +" year "+ month +" month "+ day +" day "+ hours +" Hour "+ minutes +" Minute "+ seconds +" second ";
// Set the end time
// 1 second = 1000 milliseconds
Endtime = initializationtime + 60000;
// Set and display the remaining time
VaR lefttime = math. Floor (endtime-(new date (). gettime ()/1000 );
If (lefttime> 0)
{
Document. All. showleft. innerhtml = lefttime + "stop in microseconds! ";
}
Else
{
Cleartimeout (timeid );
Document. All. showleft. innerhtml = "timeout! ";
Return false;
}
// Refresh the display time once every second
VaR timeid = setTimeout (showlefttime, 1000 );
}
// -->
</SCRIPT>