⑴ java建立一个闹钟厂,闹钟属性:形状、颜色、时间(设置为整型)闹钟行为:响铃,设
代码如下:
import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.Frame;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.io.IOException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Timer;
import java.util.TimerTask;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.Clip;
import javax.sound.sampled.LineEvent;
import javax.sound.sampled.LineListener;
import javax.sound.sampled.LineUnavailableException;
import javax.sound.sampled.UnsupportedAudioFileException;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
/**
* 闹钟主界面
*/
public class AlarmClock extends JFrame implements ActionListener {
private static final int LOOP_COUNT = 5; // 重复播放的次数
private JLabel labelClock, labelAlarm, labelNextAlarm;
private JButton btnSet, btnClose;
private SetDialog setDialog;
private JPanel topPanel, alarmPanel;
private Timer timer;
private Clip clip;
private Calendar alarmCal;
private boolean timeReached = true;
private DateFormat df = new SimpleDateFormat(