
import java.awt.EventQueue
import java.awt.event.ActionEvent
import java.awt.event.ActionListener
import java.util.Date
import javax.swing.JFrame
import javax.swing.JLabel
import javax.swing.Timer
public class TimerShow extends JFrame {
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
new TimerShow()
} catch (Exception e) {
e.printStackTrace()
}
}
})
}
private JLabel lblNewLabel
public TimerShow() {
super("time")
setBounds(100, 100, 450, 300)
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE)
getContentPane().setLayout(null)
lblNewLabel = new JLabel(" 简单时钟 ", JLabel.CENTER)
lblNewLabel.setBounds(0, (300-35-35)/2, 440, 35)
getContentPane().add(lblNewLabel)
setVisible(true)
new Timer(delay, taskPerformer).start()
}
int delay = 1000//milliseconds
ActionListener taskPerformer = new ActionListener() {
public void actionPerformed(ActionEvent evt) {
String s=String.format("粗滚%tY-%<tm-%<td %<tH:%<tM:%<tS",new Date())
lblNewLabel.setText(s)
}
}
}
你要什么样的时钟显示?如果要文字显示的话我可以给你衡并前一个
如果要图像显示的话
参考一下这个帖子,毕竟略设计到一些图形学的编程,我没那么容易将明白,知道用哪几蔽孝行就行了
具体时钟的代码在第咐清18页
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)