⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 returntime.java

📁 里面所含源码是本人平时做程序的一些实例
💻 JAVA
字号:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.*;
public class ReturnTime extends Frame 
{
	Button btnClock;
	public static Label lblClock;
	String strInput;
	//TextField txtClock;
	public ReturnTime()
	{
		
		MyEvent me=new MyEvent();
		
		lblClock=new Label("请点击'设置'按钮");
		btnClock=new Button("设置");
		btnClock.addActionListener(me);
		this.add(lblClock,"Center");
		this.add(btnClock,"South");
		this.pack();
		setTitle("倒计时表");
		this.setVisible(true);
		this.setResizable(false);
		addWindowListener(me);
	}
	public static void main(String[] args) {
		new ReturnTime();
	}

	
}
class MyEvent extends WindowAdapter implements ActionListener
{
	String strIn;
	ThreadTime tt;
	
	public void actionPerformed(ActionEvent ae)
	{
		this.setTime();
		strIn=this.getTime();
	//	ReturnTime.lblClock.setText(strIn);
		tt=new ThreadTime(strIn);
	//	Thread thread=new Thread(tt);
	//	thread.start();
	}
	public void setTime()
	{
		strIn=JOptionPane.showInputDialog(null,"请输入倒计时的分钟数:");
	}
	public String getTime()
	{
		return strIn;	
	}
	public void windowClosing(WindowEvent we)
	{
		System.exit(0);
	}
}
class ThreadTime implements Runnable
{
	String strIn;
	long time,start,end;
	public ThreadTime(String strIn)
	{
		strIn=this.strIn;
		time=1000*60*(Integer.parseInt(strIn));
		end=time+new Date().getTime();
	}
	public void run()
	{
		while(true)
		{
			start=end-(new Date().getTime());
			if(start>0){
				String strTime=this.convert(start);
				ReturnTime.lblClock.setText(strTime);
				try
				{
					Thread.sleep(10);	
				}
				catch(InterruptedException ie)
				{
					ie.printStackTrace();
				}
				
			}
			else
				break;
		}
	}
	public String convert(long ctime) 
	{
		long h=ctime/3600000;
		long m=(ctime%60000)/1000;
		long s=(ctime%1000)/10;
		long n=(ctime%10);
		String hh=h<10?"0":"";
		String mm=m<10?"0":"";
		String ss=s<10?"0":"";
		String nn=n<10?"0":"";
		String strTime=hh+":"+mm+":"+ss+":"+nn;
		return strTime;
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -