java日历闹钟代码 java中日历类

用JAVA编一个小闹钟import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.*;
import javax.swing.Timer;
public class Clock extends JFrame implements ActionListener {
public final int HEIGTH = 200, L0 = 50, T0 = 50,N=8;
public final double RAD = Math.PI / 180.0;
int x, y, old_X, old_Y, r, x0, y0, w, h, ang;
int sdo, mdo, hdo, old_M, old_H, hh, mm, ss;
int delay = 1000;
Calendar now;
String st, alarm, Items1, Items2,str[];
JButton jb;
JComboBox jc1, jc2, jc3;
JLabel jl1, jl2, jl3, jl4;
JMenu jm1, jm2, jm3, jm4;
JMenuBar jmb;
JMenuItem jmi1, jmi2, jmi3, jmi4, jmi5, jmi6, jmi7, jmi8, jmi9,jmi10;
JTextField jtf1, jtf2, time;
JPanel jp1, jp2, jp3;
Timer timer;
TimeZone tz = TimeZone.getTimeZone("JST");
Toolkit toolkit=Toolkit.getDefaultToolkit();;
/**
* br
* 方法说明:实现ActionListener类必须过载的方法
*/
public static void main(String[] args) {
Clock cp = new Clock();
cp.setVisible(true);
}
Clock() {
super("Java闹钟!");
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
setSize(550, 700);
setVisible(true);
Container contentPane = getContentPane();
jp2 = new JPanel();
jmb = new JMenuBar();
jm1 = new JMenu("背景颜色设置", true);
jmi1 = new JMenuItem("外圈颜色");
jmi1.addActionListener(this);
jmi1.setActionCommand("color1");
jm1.add(jmi1);
jmi2 = new JMenuItem("闹钟边线颜色");
jmi2.addActionListener(this);
jmi2.setActionCommand("color2");
jm1.add(jmi2);
jmi3=new JMenuItem("底盘颜色");
jmi3.addActionListener(this);
jmi3.setActionCommand("color3");
jm1.add(jmi3);
jmi4=new JMenuItem("系统时间背静颜色");
jmi4.addActionListener(this);
jmi4.setActionCommand("color4");
jm1.add(jmi4);
jmb.add(jm1);
jm2 = new JMenu("指针颜色设置", true);
jmi5 = new JMenuItem("秒针颜色");
jmi5.addActionListener(this);
jmi5.setActionCommand("color5");
jm2.add(jmi5);
jmi6 = new JMenuItem("分针颜色");
jmi6.addActionListener(this);
jmi6.setActionCommand("color6");
jm2.add(jmi6);
jmi7 = new JMenuItem("时针颜色");
jmi7.addActionListener(this);
jmi7.setActionCommand("color7");
jm2.add(jmi7);
jmb.add(jm2);
jm3 = new JMenu("闹铃声音设置", true);
jmi8 = new JMenuItem("响铃1");
jmi8.addActionListener(this);
jmi8.setActionCommand("ring1");
jm3.add(jmi8);
jmi9 = new JMenuItem("静音");
jmi9.addActionListener(this);
jmi9.setActionCommand("ring2");
jm3.add(jmi9);
jmb.add(jm3);
jm4 = new JMenu("帮助", true);
jmi10=new JMenuItem("使用说明");
jmi10.addActionListener(this);
jmi10.setActionCommand("help");
jm4.add(jmi10);
jmb.add(jm4);
jp2.add(jmb);
contentPane.add(jp2, BorderLayout.NORTH);
jp3 = new JPanel();
jl1 = new JLabel("闹铃时间");
jl1.setFont(new Font("楷体_GB2312", Font.BOLD, 18));
time = new JTextField("00:00", 5);
alarm = time.getText();
jb = new JButton("修改闹铃时间");
jb.addActionListener(this);
jb.setActionCommand("CC");
jp3.add(jl1);
jp3.add(time);
jp3.add(jb);
contentPane.add(jp3, BorderLayout.SOUTH);
ClockPanel clock = new ClockPanel();
contentPane.add(clock, BorderLayout.CENTER);
// 窗体添加事件监听,监听秒表的触发
ActionListener taskPerformer = new ActionListener() {
public void actionPerformed(ActionEvent evt) {
repaint();
}
};
new Timer(delay, taskPerformer).start();
}
/**
* br
* 方法说明:绘制图形
*/

推荐阅读