package 第十一章; import java.awt.Button; import java.awt.Color; import java.awt.Font; import java.awt.Frame; import java.awt.Label; import java.awt.Panel; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.util.*; public class shijian extends Frame{ Panel pan=new Panel(); Label lbl=new Label(); Button btn=new Button("开始"); public shijian(String str) { super(str); } public shijian(){ buju(); } public static void main(String agrs[]){ shijian sj=new shijian(); } public void buju(){ shijian f=new shijian("显示时间"); f.setSize(500,500); f.setBackground(Color.gray); f.setLayout(null); f.setVisible(true); pan.setSize(500, 500); pan.setLocation(0, 0); pan.setBackground(Color.darkGray); pan.setLayout(null); lbl.setSize(300,100); lbl.setLocation(100, 100); lbl.setBackground(Color.yellow); // lbl.setFont(); Font kl=new Font("宋体",0,25); lbl.setFont(kl); btn.setSize(100,50); btn.setLocation(200, 250); btn.addActionListener(new ActionListener(){ @Override public void actionPerformed(ActionEvent e) { // TODO Auto-generated method stub // if(btn.s) kaishi(e); }}); pan.add(btn); pan.add(lbl); f.add(pan); } public void kaishi(ActionEvent e){ while(true){ Date d=new Date(); // long l1=d.getTime(); lbl.setText(d.toLocaleString()); try { Thread.sleep(1000); } catch (InterruptedException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } } } }