⑴ 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(