1个回答
展开全部
package com.exam.student.reserve;
import java.awt.*;
import javax.swing.*;
import java.util.*;
public class Time extends JFrame
{
JPanel pnlmain;
static JLabel lblmove;
JButton bntcontrol;
currenttime ct;
public Time()
{
pnlmain=new JPanel();
this.setContentPane(pnlmain);
lblmove=new JLabel("你好");
lblmove.setFont(new Font("宋体",Font.BOLD,22));
lblmove.setForeground(Color.RED);
pnlmain.add(lblmove);
ct=new currenttime();
ct.start();
setTitle("线程");
setSize(250,150);
setVisible(true);
setDefaultCloseOperation(EXIT_ON_CLOSE);
setResizable(false);
}
public static void main(String args[])
{
new Time();
}
}
class currenttime extends Thread
{
Date datedisplay;
GregorianCalendar gccalendar;
String strtime;
public currenttime(){}
public void run()
{
while(true)
{
displaytime();
try
{
this.sleep(1000);
}
catch(InterruptedException e)
{
JOptionPane.showMessageDialog(null,"线程中断");
}
}
}
public void displaytime()
{
datedisplay=new Date();
gccalendar=new GregorianCalendar();
gccalendar.setTime(datedisplay);
strtime="当前时间:"+gccalendar.get(Calendar.DATE)+":"+gccalendar.get(Calendar.HOUR)+":"+gccalendar.get(Calendar.MINUTE)+":"+gccalendar.get(Calendar.SECOND);
Time.lblmove.setText(strtime);
}
}
import java.awt.*;
import javax.swing.*;
import java.util.*;
public class Time extends JFrame
{
JPanel pnlmain;
static JLabel lblmove;
JButton bntcontrol;
currenttime ct;
public Time()
{
pnlmain=new JPanel();
this.setContentPane(pnlmain);
lblmove=new JLabel("你好");
lblmove.setFont(new Font("宋体",Font.BOLD,22));
lblmove.setForeground(Color.RED);
pnlmain.add(lblmove);
ct=new currenttime();
ct.start();
setTitle("线程");
setSize(250,150);
setVisible(true);
setDefaultCloseOperation(EXIT_ON_CLOSE);
setResizable(false);
}
public static void main(String args[])
{
new Time();
}
}
class currenttime extends Thread
{
Date datedisplay;
GregorianCalendar gccalendar;
String strtime;
public currenttime(){}
public void run()
{
while(true)
{
displaytime();
try
{
this.sleep(1000);
}
catch(InterruptedException e)
{
JOptionPane.showMessageDialog(null,"线程中断");
}
}
}
public void displaytime()
{
datedisplay=new Date();
gccalendar=new GregorianCalendar();
gccalendar.setTime(datedisplay);
strtime="当前时间:"+gccalendar.get(Calendar.DATE)+":"+gccalendar.get(Calendar.HOUR)+":"+gccalendar.get(Calendar.MINUTE)+":"+gccalendar.get(Calendar.SECOND);
Time.lblmove.setText(strtime);
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询