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

📄 clock.java

📁 里面所含源码是本人平时做程序的一些实例
💻 JAVA
字号:
import javax.swing.*;
import java.util.*;
import java.awt.*;
public class Clock extends JFrame implements Runnable{
	Date d;
	GregorianCalendar gcCalendar;
	String strTime;
	Thread tClock;
	JPanel pnlMain;
	JLabel lblClock;
	public Clock(){
		
		pnlMain=new JPanel();
		lblClock=new JLabel("sdfsdf");
		setContentPane(pnlMain);
		tClock=new Thread(this);
		lblClock.setForeground(Color.red);
		lblClock.setFont(new Font("宋体",Font.BOLD,30));
		pnlMain.add(lblClock,"Center");
		tClock.start();
		pack();
		
		setVisible(true);
		setResizable(false);
		setDefaultCloseOperation(2);
	}
	public void run(){
		while(tClock!=null)
		{
			d=new Date();
			gcCalendar=new GregorianCalendar();
			gcCalendar.setTime(d);
			String h,m,s;
			h=gcCalendar.get(Calendar.HOUR)>9?"":"0";
			m=gcCalendar.get(Calendar.MINUTE)>9?"":"0";
			s=gcCalendar.get(Calendar.SECOND)>9?"":"0";
			String strDate="当前日期:"+gcCalendar.get(Calendar.YEAR)+
			"-"+gcCalendar.get(Calendar.MONTH+1)+"-"+
			gcCalendar.get(Calendar.DATE);
			strTime="当前时间:"+h+gcCalendar.get(Calendar.HOUR)+":"+m+gcCalendar.get(Calendar.MINUTE)+
			":"+s+gcCalendar.get(Calendar.SECOND);		
			lblClock.setText(strDate+"\r\n"+strTime);
			try
			{
				tClock.sleep(1000);
			}
			catch(InterruptedException ie){JOptionPane.showMessageDialog(null,"线程中断!");}
		}
	}

}

⌨️ 快捷键说明

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