import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
public class Timer extends JFrame
{
Pane1 p1;
Pane2 p2;
Timer()
{
super("日历");
JPanel pan=new JPanel();
pan.setLayout(new GridLayout(2,1,5,5));
p1=new Pane1();p2=new Pane2();
pan.add(p1);
pan.add(p2);
setSize(200,300);
setContentPane(pan);
}
public static void main(String[] args)
{
JFrame tt=new Timer();
tt.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
tt.setVisible(true);
}
}
class Pane1 extends JPanel
{
private JLabel Mon,Tus,Wen,Thir,Fir,Stat,Sun;
Pane1()
{
Mon=new JLabel("一");
Tus=new JLabel("二");
Wen=new JLabel("三");
Thir=new JLabel("四");
Fir=new JLabel("五");
Stat=new JLabel("六");
Sun=new JLabel("日");
add(Mon);add(Tus);add(Wen);add(Thir);add(Fir);add(Stat); add(Sun);
}
}
class Pane2 extends JPanel implements ActionListener ///就是这个面板不能显示出来.编译和执行都可以.
{
private JLabel showTime;
Pane2()
{
showTime=new JLabel("");
add(showTime);
}
public void actionPerformed(ActionEvent e)
{
try {
Calendar d=Calendar.getInstance();
int hour=d.get(Calendar.HOUR);
int min=d.get(Calendar.MINUTE);
int sec=d.get(Calendar.SECOND);
Thread.sleep(1000);
showTime.setText("现在时间是:"+hour+"时:"+min+"分:"+sec+"秒");
}
catch (Exception ex) {
}
}
}