項目結構:
效果圖一:
效果圖二:
效果圖三:
關於鬧鐘:
代碼如下:
Alarm hongten v1.0
使用說明:
此文件夾中包括:
src文件夾 存放圖片和聲音文件夾,使用程序的時候,請不要刪除此文件夾
alarm.jar 主要的功能程序jar包(要求安裝jdk1.5或以上版本)
ReadMe.txt 說明文檔
1.菜單功能說明
文件—— >
上傳鈴聲(還沒實現)
退出 功能:退出程序
工具—— >
截圖工具 功能:進行截圖
更改背景 功能:更改背景
幫助—— >
關於程序 功能:查看程序說明
2.設置鬧表
2.1.可以在響鈴時間裡設置鬧表時間
2.2.還可以用快速設置,+1表示在系統時間的基礎上增加一分鐘,-1表示在系統時間的基礎上減去一分鐘 (+5,+30,-5,-30同樣原理)
3.提示鈴聲
可以選擇鈴聲類型,進行試聽,試聽是時候可以停止(該功能還沒完善)
4.系統托盤
4.1.在主窗體隱藏的時候,單擊左鍵,主窗體可以顯示出來;
4.2.在主窗體隱藏的時候,單擊右鍵,可以進行功能選擇:退出,恢復主窗體可見,截圖
4.3.在設置的鬧表時間剩下30秒是時候,系統會自動提示信息(電腦右下角會彈出消息提示框)
4.4.在設置更改背景的時候,同樣會彈出提示信息(所有的提示信息會自動隱退)
下面是代碼部分
==========================================================
/Alarm/src/com/b510/main/AlarmMain.java
代碼如下:
package com.b510.main;
import com.b510.ui.main.MyAlarm;
/**
*
* @author Hongten
*/
public class AlarmMain {
public static void main(String[] args) {
new MyAlarm("Alarm hongten v-1.0");
}
}
/Alarm/src/com/b510/menu/AlarmBackground.java
代碼如下:
package com.b510.menu;
/**
* @author Hongten
*
* @time 2012-3-4 2012
*/
public class AlarmBackground {
/**
* 默認的背景圖片
*/
private static String BACKGROUND_DEFAULT="src/image/background.png";
/**
* 水果系列
*/
private static String BACKGROUND_FRUIT="src/image/background1.png";
/**
* 自行車系列
*/
private static String BACKGROUND_BICK="src/image/background2.png";
/**
* 背景圖片的list
*/
private static String[] backgroundList={BACKGROUND_DEFAULT,BACKGROUND_FRUIT,BACKGROUND_BICK};
/**
* 獲取背景圖片的list的長度
* @return 返回背景圖片的list的長度
*/
public static int getBackgroundListSize(){
return backgroundList.length;
}
public static String getBackground(int bg){
return backgroundList[bg];
}
}
/Alarm/src/com/b510/menu/AlarmFile.java
代碼如下:
package com.b510.menu;
/**
*
* @author Hongten
* 菜單-文件
*/
public class AlarmFile {
/**
* 退出程序
*/
public static void exit(){
System.exit(0);
}
}
/Alarm/src/com/b510/menu/AlarmHelp.java
代碼如下:
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package com.b510.menu;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import com.b510.ui.main.MyAlarm;
/**
*
* @author Hongten 菜單-幫助
*/
public class AlarmHelp extends JFrame {
/**
* 版本號
*/
private static final long serialVersionUID = 5248482602468160509L;
public AlarmHelp(String title) {
super(title);
initComponents();
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
AlarmHelp.this.setVisible(false);
}});
}
/**
*關閉按鈕
*/
private JButton closeButton = new JButton();
/**
* 應用程序名稱
*/
javax.swing.JLabel appTitleLabel = new javax.swing.JLabel();
/**
* 版本號 前
*/
javax.swing.JLabel versionLabel = new javax.swing.JLabel();
/**
* 版本號
*/
javax.swing.JLabel appVersionLabel = new javax.swing.JLabel();
/**
* 主頁 前
*/
javax.swing.JLabel homepageLabel = new javax.swing.JLabel();
/**
* Homepage
*/
javax.swing.JLabel appHomepageLabel = new javax.swing.JLabel();
/**
* 說明
*/
javax.swing.JLabel appDescLabel = new javax.swing.JLabel();
/**
* 圖片
*/
javax.swing.JLabel imageLabel = new javax.swing.JLabel();
private void initComponents() {
this.setVisible(true);
// 設置大小不能變
setResizable(false);
this.setLocation(MyAlarm.pointX+60, MyAlarm.pointY+190);// 設置窗體的初始位置
closeButton.addMouseListener(new MouseAdapter() {
public void mouseEntered(java.awt.event.MouseEvent evt) {
closeButton.setIcon(new ImageIcon("src/image/biao2.png"));
}
public void mouseExited(MouseEvent evt){
closeButton.setIcon(new ImageIcon("src/image/biao.png"));
}
});
appTitleLabel.setFont(appTitleLabel.getFont().deriveFont(
appTitleLabel.getFont().getStyle() | java.awt.Font.BOLD,
appTitleLabel.getFont().getSize() + 4));
appTitleLabel.setText("應用程序名稱:"); // NOI18N
appTitleLabel.setName("appTitleLabel"); // NOI18N
versionLabel.setFont(versionLabel.getFont().deriveFont(
versionLabel.getFont().getStyle() | java.awt.Font.BOLD));
versionLabel.setText("版本號:"); // NOI18N
versionLabel.setName("versionLabel"); // NOI18N
appVersionLabel.setText("1.0"); // NOI18N
appVersionLabel.setName("appVersionLabel"); // NOI18N
homepageLabel.setFont(homepageLabel.getFont().deriveFont(
homepageLabel.getFont().getStyle() | java.awt.Font.BOLD));
homepageLabel.setText("主頁:"); // NOI18N
homepageLabel.setName("homepageLabel"); // NOI18N
appHomepageLabel.setText("http://www.cnblogs.com/hongten"); // NOI18N
appHomepageLabel.setName("appHomepageLabel"); // NOI18N
appDescLabel.setText("這是一個小應用程序,鬧鐘"); // NOI18N
appDescLabel.setName("appDescLabel"); // NOI18N
imageLabel
.setIcon(new ImageIcon("src/image/about.png")); // NOI18N
imageLabel.setName("imageLabel"); // NOI18N
closeButton
.setIcon(new ImageIcon("src/image/biao.png"));
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(
getContentPane());
getContentPane().setLayout(layout);
layout
.setHorizontalGroup(layout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(
layout
.createSequentialGroup()
.addComponent(imageLabel)
.addGap(18, 18, 18)
.addGroup(
layout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.TRAILING)
.addGroup(
javax.swing.GroupLayout.Alignment.LEADING,
layout
.createSequentialGroup()
.addGroup(
layout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(
versionLabel)
.addComponent(
homepageLabel))
.addPreferredGap(
javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(
layout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(
appVersionLabel)
.addComponent(
appHomepageLabel)))
.addComponent(
appTitleLabel,
javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(
appDescLabel,
javax.swing.GroupLayout.Alignment.LEADING,
javax.swing.GroupLayout.DEFAULT_SIZE,
266,
Short.MAX_VALUE)
.addComponent(
closeButton))
.addContainerGap()));
layout
.setVerticalGroup(layout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(imageLabel,
javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
Short.MAX_VALUE)
.addGroup(
layout
.createSequentialGroup()
.addContainerGap()
.addComponent(appTitleLabel)
.addPreferredGap(
javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(
appDescLabel,
javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(
javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(
layout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(
versionLabel)
.addComponent(
appVersionLabel))
.addPreferredGap(
javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(
layout
.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE))
.addPreferredGap(
javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(
layout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(
homepageLabel)
.addComponent(
appHomepageLabel))
.addPreferredGap(
javax.swing.LayoutStyle.ComponentPlacement.RELATED,
19, Short.MAX_VALUE)
.addComponent(closeButton)
.addContainerGap()));
pack();
}
}
/Alarm/src/com/b510/menu/AlarmTools.java
代碼如下:
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package com.b510.menu;
import mai.capture.DesktopCapture;
/**
*
* @author Hongten
* 菜單-工具
*/
public class AlarmTools {
/** 定義截圖功能 */
@SuppressWarnings("unused")
private static DesktopCapture deskTopCapture;
/**
* 截圖
*/
public static void screenshot(){
deskTopCapture=new DesktopCapture();
}
}
/Alarm/src/com/b510/ui/main/MyAlarm.java
代碼如下:
package com.b510.ui.main;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Point;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.File;
import java.io.IOException;
import java.util.Calendar;
import javax.sound.sampled.AudioFormat;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.DataLine;
import javax.sound.sampled.SourceDataLine;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import com.b510.menu.AlarmBackground;
import com.b510.menu.AlarmFile;
import com.b510.menu.AlarmHelp;
import com.b510.menu.AlarmTools;
/**
*
* @author Hongten
*/
public class MyAlarm extends JFrame implements ActionListener {
/**
*+1
*/
private javax.swing.JButton add1;
/**
* +30
*/
private javax.swing.JButton add30;
/**
* +5
*/
private javax.swing.JButton add5;
/**
* 時
*/
private javax.swing.JComboBox dorp_down_hours;
/**
* 分
*/
private javax.swing.JComboBox dorp_down_minute;
/**
* 秒
*/
private javax.swing.JComboBox drop_down_second;
/**
* 試聽
*/
private javax.swing.JButton listening_test;
/**
* 試聽-停止
*/
private javax.swing.JButton listening_test_stop;
/**
* 主Panel
*/
private javax.swing.JPanel mainPanel;
/**
* 菜單bar
*/
private javax.swing.JMenuBar menuBar;
/**
* -1
*/
private javax.swing.JButton minus1;
/**
* -30
*/
private javax.swing.JButton minus30;
/**
* -5
*/
private javax.swing.JButton minus5;
/**
* 當前時間
*/
private javax.swing.JLabel now;
/**
* 鈴聲
*/
private javax.swing.JComboBox ring_setup;
/**
* 截屏
*/
private javax.swing.JMenuItem screenshot;
/**
* 更改背景圖片
*/
private javax.swing.JMenuItem changeBackground;
/**
* 停止
*/
private javax.swing.JButton stop;
/**
* 工具
*/
private javax.swing.JMenu tools;
/**
* 幫助
*/
private javax.swing.JMenu help;
/**
* 關於
*/
private javax.swing.JMenuItem about;
/**
* 退出
*/
private javax.swing.JMenuItem exit;
/**
* 上傳鈴聲
*/
private javax.swing.JMenuItem uploadRing;
/**
* wenjian
*/
private javax.swing.JMenu file;
/**
* 結果,即剩余時間
*/
private JLabel result;
/**
* 分割線
*/
private javax.swing.JSeparator line;
/**
* 變量-->小時
*/
private String h;
/**
* 變量-->分鐘
*/
private String m;
/**
* 變量-->秒
*/
private String s;
/**
* 線程的一個標志
*/
private boolean running = true;
/**
* 定義圖盤圖盤標志
*/
public boolean iconed = false;
/**
* 背景圖片選擇標志
*/
private int background = 0;
/**
* 獲取result的秒數
*/
private int secondOfResult;
/**
* 更改背景圖片的標志
*/
private boolean flagOfBackground = false;
/**
* MyAlarm的X坐標
*/
public static int pointX = 0;
/**
* MyAlarm的Y坐標
*/
public static int pointY = 0;
/** 定義托盤 */
MyTray myTray;
/**
* 版本號
*/
private static final long serialVersionUID = -6601825053136983041L;
public MyAlarm(String title) {
this.setTitle(title);
init();
}
/**
* 初始化背景圖片
*/
public void initMainPanel() {
mainPanel = new JPanel() {
private static final long serialVersionUID = 1L;
protected void paintComponent(Graphics g) {
ImageIcon icon = new ImageIcon(AlarmBackground
.getBackground(background));
g.drawImage(icon.getImage(), 0, 0, 545, 463, null);
}
};
}
/**
* 主界面初始化
*/
public void init() {
initMainPanel();
now = new javax.swing.JLabel();
stop = new javax.swing.JButton();
add1 = new javax.swing.JButton();
add5 = new javax.swing.JButton();
add30 = new javax.swing.JButton();
minus1 = new javax.swing.JButton();
minus5 = new javax.swing.JButton();
minus30 = new javax.swing.JButton();
listening_test = new javax.swing.JButton();
listening_test_stop = new javax.swing.JButton();
dorp_down_hours = new javax.swing.JComboBox();
dorp_down_minute = new javax.swing.JComboBox();
drop_down_second = new javax.swing.JComboBox();
ring_setup = new javax.swing.JComboBox();
menuBar = new javax.swing.JMenuBar();
file = new javax.swing.JMenu();
uploadRing = new javax.swing.JMenuItem();
exit = new javax.swing.JMenuItem();
tools = new javax.swing.JMenu();
screenshot = new javax.swing.JMenuItem();
changeBackground = new javax.swing.JMenuItem();
help = new javax.swing.JMenu();
about = new javax.swing.JMenuItem();
line = new javax.swing.JSeparator();
result = new javax.swing.JLabel();
mainPanel.setName("mainPanel"); // NOI18N
result.setForeground(Color.RED);
result.setName("result");
result.setVisible(false);
now.setFont(now.getFont().deriveFont(
now.getFont().getStyle() | java.awt.Font.BOLD,
now.getFont().getSize() + 70));
now.setName("now"); // NOI18N
// 時間監聽器,得到系統時間和設置好時間後,得到剩余時間
timeListener();
stop.setText("stop"); // NOI18N
stop.setName("stop"); // NOI18N
// 初始化的時候是不可見的
stop.setVisible(false);
stop.addActionListener(this);
add1.setText("+1"); // NOI18N
add1.setName("add1"); // NOI18N
add1.addActionListener(this);
add5.setText("+5"); // NOI18N
add5.setName("add5"); // NOI18N
add5.addActionListener(this);
add30.setText("+30"); // NOI18N
add30.setName("add30"); // NOI18N
add30.addActionListener(this);
minus1.setText("-1"); // NOI18N
minus1.setName("minus1"); // NOI18N
minus1.addActionListener(this);
minus5.setText("-5"); // NOI18N
minus5.setName("minus5"); // NOI18N
minus5.addActionListener(this);
minus30.setText("-30"); // NOI18N
minus30.setName("minus30"); // NOI18N
minus30.addActionListener(this);
listening_test.setText("試聽"); // NOI18N
listening_test.setName("listening_test"); // NOI18N
listening_test.addActionListener(this);
listening_test_stop.setText("停止"); // NOI18N
listening_test_stop.setName("listening_test_stop"); // NOI18N
listening_test_stop.addActionListener(this);
dorp_down_hours.setModel(new javax.swing.DefaultComboBoxModel(
new String[] { "關閉", "00", "01", "02", "03", "04", "05", "06",
"07", "08", "09", "10", "11", "12", "13", "14", "15",
"16", "17", "18", "19", "20", "21", "22", "23" }));
dorp_down_hours.setName("dorp_down_hours"); // NOI18N
dorp_down_hours.addActionListener(this);
dorp_down_minute.setModel(new javax.swing.DefaultComboBoxModel(
new String[] { "關閉", "00", "01", "02", "03", "04", "05", "06",
"07", "08", "09", "10", "11", "12", "13", "14", "15",
"16", "17", "18", "19", "20", "21", "22", "23", "24",
"25", "26", "27", "28", "29", "30", "31", "32", "33",
"34", "35", "36", "37", "38", "39", "40", "41", "42",
"43", "44", "45", "46", "47", "48", "49", "50", "51",
"52", "53", "54", "55", "56", "57", "58", "59" }));
dorp_down_minute.setName("dorp_down_minute"); // NOI18N
dorp_down_minute.addActionListener(this);
drop_down_second.setModel(new javax.swing.DefaultComboBoxModel(
new String[] { "關閉", "00", "01", "02", "03", "04", "05", "06",
"07", "08", "09", "10", "11", "12", "13", "14", "15",
"16", "17", "18", "19", "20", "21", "22", "23", "24",
"25", "26", "27", "28", "29", "30", "31", "32", "33",
"34", "35", "36", "37", "38", "39", "40", "41", "42",
"43", "44", "45", "46", "47", "48", "49", "50", "51",
"52", "53", "54", "55", "56", "57", "58", "59" }));
drop_down_second.setName("drop_down_second"); // NOI18N
drop_down_second.addActionListener(this);
ring_setup.setModel(new javax.swing.DefaultComboBoxModel(new String[] {
"鈴聲一", "鈴聲二", "鈴聲三", "鈴聲四", "鈴聲五", "鈴聲六", "鈴聲七" }));
ring_setup.setName("ring_setup"); // NOI18N
// 主要的布局
omponentLayout();
menuBar.setName("menuBar"); // NOI18N
file.setText("文件"); // NOI18N
file.setName("file"); // NOI18N
uploadRing.setText("上傳鈴聲"); // NOI18N
uploadRing.setName("uploadRing"); // NOI18N
uploadRing.addActionListener(this);
file.add(uploadRing);
file.add(line);
exit.setText("退出");
exit.setName("exit"); // NOI18N
exit.addActionListener(this);
file.add(exit);
menuBar.add(file);
tools.setText("工具"); // NOI18N
tools.setName("tools"); // NOI18N
screenshot.setText("截圖工具"); // NOI18N
screenshot.setName("screenshot"); // NOI18N
screenshot.addActionListener(this);
tools.add(screenshot);
changeBackground.setText("更改背景");
changeBackground.setName("changeBackground");
changeBackground.addActionListener(this);
tools.add(changeBackground);
menuBar.add(tools);
help.setText("幫助"); // NOI18N
help.setName("help"); // NOI18N
about.setText("關於軟件");
about.setName("about"); // NOI18N
about.addActionListener(this);
help.add(about);
menuBar.add(help);
this.add(mainPanel);
setJMenuBar(menuBar);
this.setVisible(true);
this.setSize(550, 516);
// this.pack();
this.setLocationRelativeTo(null);
this.setResizable(false);
// this.setLocation(470, 250);
// this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
// 當點擊"-"最小化按鈕時,系統會最小化到托盤
addWindowListener(new WindowAdapter() {
public void windowIconified(WindowEvent e) {
iconed = true;
setVisible(false);
}
public void windowClosing(WindowEvent e) {
// 當點擊"X"關閉窗口按鈕時,會詢問用戶是否要最小化到托盤
// 是,表示最小化到托盤,否,表示退出
int option = JOptionPane.showConfirmDialog(MyAlarm.this,
"是否最小化到托盤?", "提示:", JOptionPane.YES_NO_OPTION);
if (option == JOptionPane.YES_OPTION) {
iconed = true;
MyAlarm.this.setVisible(false);
} else {
AlarmFile.exit();
}
}
});
// 初始化自定義托盤
myTray = new MyTray(MyAlarm.this);
}
/**
* 組件的布局,不要輕易動啊
*/
private void omponentLayout() {
javax.swing.GroupLayout mainPanelLayout = new javax.swing.GroupLayout(
mainPanel);
mainPanel.setLayout(mainPanelLayout);
mainPanelLayout
.setHorizontalGroup(mainPanelLayout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(
javax.swing.GroupLayout.Alignment.TRAILING,
mainPanelLayout
.createSequentialGroup()
.addContainerGap(170, Short.MAX_VALUE)
.addGroup(
mainPanelLayout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(
mainPanelLayout
.createSequentialGroup()
.addComponent(
result)
.addContainerGap())
.addGroup(
javax.swing.GroupLayout.Alignment.TRAILING,
mainPanelLayout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(
mainPanelLayout
.createSequentialGroup()
.addComponent(
now,
javax.swing.GroupLayout.DEFAULT_SIZE,
483,
Short.MAX_VALUE)
.addContainerGap())
.addGroup(
javax.swing.GroupLayout.Alignment.TRAILING,
mainPanelLayout
.createSequentialGroup()
.addGroup(
mainPanelLayout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(
mainPanelLayout
.createSequentialGroup()
.addComponent(
dorp_down_hours,
javax.swing.GroupLayout.PREFERRED_SIZE,
74,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(
javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(
dorp_down_minute,
javax.swing.GroupLayout.PREFERRED_SIZE,
65,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(
javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(
drop_down_second,
javax.swing.GroupLayout.PREFERRED_SIZE,
62,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(
javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(
stop))
.addGroup(
mainPanelLayout
.createSequentialGroup()
.addComponent(
add1)
.addPreferredGap(
javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(
add5)
.addPreferredGap(
javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(
add30)
.addPreferredGap(
javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(
minus1)
.addPreferredGap(
javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(
minus5)
.addPreferredGap(
javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(
minus30))
.addGroup(
mainPanelLayout
.createSequentialGroup()
.addComponent(
ring_setup,
javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(
javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(
listening_test)
.addPreferredGap(
javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(
listening_test_stop)))
.addGap(
73,
73,
73))))));
mainPanelLayout
.setVerticalGroup(mainPanelLayout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(
javax.swing.GroupLayout.Alignment.TRAILING,
mainPanelLayout
.createSequentialGroup()
.addGap(120, 120, 120)
.addComponent(result)
.addGap(24, 24, 24)
.addComponent(
now,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
Short.MAX_VALUE)
.addGap(36, 36, 36)
.addGroup(
mainPanelLayout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(
dorp_down_hours,
javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(
dorp_down_minute,
javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(
drop_down_second,
javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(stop))
.addPreferredGap(
javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(
mainPanelLayout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(add1)
.addComponent(add5)
.addComponent(add30)
.addComponent(minus1)
.addComponent(minus5)
.addComponent(minus30))
.addGap(13, 13, 13)
.addGroup(
mainPanelLayout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(
ring_setup,
javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(
listening_test)
.addComponent(
listening_test_stop))
.addGap(58, 58, 58)));
}
/**
* 時間監聽器,得到系統時間和設置好時間後,得到剩余時間
*/
public void timeListener() {
new Thread(new Runnable() {// 設置一個線程
public void run() {
while (true) {
try {
Thread.sleep(1000);
} catch (Exception e) {
e.printStackTrace();
}
initMainPanel();
now.setText(now());// 得到系統時間
result.setText(surplus_time());// 得到剩余時間
}
}
}).start();
}
/**
* 播放聲音的監聽器
*/
public void myListener() {
new Thread(new Runnable() {// 設置一個線程
public void run() {
while (true) {
try {
Thread.sleep(1000);
} catch (Exception e) {
e.printStackTrace();
}
executeSound();// 播放聲音
}
}
}).start();
}
/**
* 獲取返回結果
*
* @return result值
*/
public String surplus_time() {
String r = null;
// 獲取系統時,分,秒
int h = getHour();
int m = getMunite();
int s = getSecond();
// 獲取設置的響鈴時間
int dh = 0;
int dm = 0;
int ds = 0;
if (dorp_down_hours.getSelectedIndex() != 0) {
dh = dorp_down_hours.getSelectedIndex() - 1;
}
if (dorp_down_minute.getSelectedIndex() != 0) {
dm = dorp_down_minute.getSelectedIndex() - 1;
}
if (drop_down_second.getSelectedIndex() != 0) {
ds = drop_down_second.getSelectedIndex() - 1;
}
int hour = dh - h;
int min = dm - m;
int sec = ds - s;
if (hour == 0) {
if (min == 0) {
if (sec == 0) {
r = "時間到了哦!";
}
if (sec < 0) {
hour += 23;
min += 59;
sec += 59;
}
}
if (min < 0) {
hour += 23;
if (sec < 0) {
min -= 1;
sec += 59;
}
min += 60;
}
if (min >= 0) {
if (sec < 0 || sec == 0) {
min -= 1;
sec += 59;
}
if (sec > 0) {
// sec=sec;
}
}
}
if (hour < 0) {
if (min <= 0) {
if (sec <= 0) {
hour -= 1;
min += 59;
sec += 59;
}
}
if (min > 0) {
if (sec <= 0) {
min -= 1;
sec += 59;
}
}
hour += 24;
}
if (hour > 0) {
if (min == 0) {
if (sec <= 0) {
hour -= 1;
min += 59;
sec += 59;
}
}
if (min < 0) {
if (sec < 0) {
min -= 1;
sec += 59;
}
min += 60;
hour -= 1;
}
if (min > 0) {
if (sec < 0 || sec == 0) {
min -= 1;
sec += 59;
}
}
}
if (sec == 30 && min == 0 && hour == 0) {
setSecondOfResult(sec);
}
r = new String("剩:" + hour + "時" + min + "分" + sec + "秒");
if (hour == 0 && min == 0 && sec < 0) {
r = "時間到了哦!";
}
// result.setText(r);
return r;
}
public int getSecondOfResult() {
return secondOfResult;
}
public void setSecondOfResult(int sec) {
this.secondOfResult = sec;
}
public boolean getFlagOfBackground() {
return flagOfBackground;
}
public void setFlagOfBackground(boolean flag) {
this.flagOfBackground = flag;
}
/**
* 時間到了的時候就播放聲音
*/
public void executeSound() {
// 獲取系統時,分,秒
int h = getHour();
int m = getMunite();
int s = getSecond();
// 獲取設置的響鈴時間
int dh = 0;
int dm = 0;
int ds = 0;
if (dorp_down_hours.getSelectedIndex() != 0) {
dh = dorp_down_hours.getSelectedIndex() - 1;
}
if (dorp_down_minute.getSelectedIndex() != 0) {
dm = dorp_down_minute.getSelectedIndex() - 1;
}
if (drop_down_second.getSelectedIndex() != 0) {
ds = drop_down_second.getSelectedIndex() - 1;
}
int hour = dh - h;
int min = dm - m;
int sec = ds - s;
if (hour == 0 && min == 0 && sec == 0) {
// 主窗體設置為可見
setVisible(true);
// 設置窗口前端顯示
setExtendedState(JFrame.NORMAL);
setAlwaysOnTop(true);
// 播放聲音
new Thread(new AlarmSound(ring_setup.getSelectedIndex())).start();
// 震動
shack();
}
}
/**
* 得到系統時間當前時間,並返回
*
* @return 返回系統當前時間
*/
public String now() {
Calendar calendar = Calendar.getInstance();
int hour = calendar.get(Calendar.HOUR_OF_DAY);
int min = calendar.get(Calendar.MINUTE);
int sec = calendar.get(Calendar.SECOND);
// 小於10的時候,在前面加0
String h = hour < 10 ? "0" : "";
String m = min < 10 ? "0" : "";
String s = sec < 10 ? "0" : "";
String current = new String(h + hour + ":" + m + min + ":" + s + sec);
return current;
}
/**
* 布局下面的按鈕和下拉選項的監聽器
*/
@SuppressWarnings("deprecation")
@Override
public void actionPerformed(ActionEvent e) {
/**
* 獲取dorp_down_hours,dorp_down_minute,drop_down_second的值
*/
if (e.getSource() == dorp_down_hours) {
valueJudgment();
}
if (e.getSource() == dorp_down_minute) {
valueJudgment();
}
if (e.getSource() == drop_down_second) {
valueJudgment();
}
if (e.getSource() == stop) {
stopActionPerformed();
}
if (e.getSource() == add1) {
add1Action();
myListener();
}
if (e.getSource() == add5) {
add5Action();
myListener();
}
if (e.getSource() == add30) {
add30Action();
myListener();
}
if (e.getSource() == minus1) {
minus1Action();
myListener();
}
if (e.getSource() == minus5) {
minus5Action();
myListener();
}
if (e.getSource() == minus30) {
minus30Action();
myListener();
}
AlarmSound alarmSound = new AlarmSound(ring_setup.getSelectedIndex());
Thread alarmThread = new Thread(alarmSound);
if (e.getSource() == listening_test) {
// 試聽
if (!alarmThread.isAlive()) {
alarmThread.start();
}
if (running) {
alarmThread.resume();
}
listening_test.setEnabled(false);
}
if (e.getSource() == listening_test_stop) {
// 停止試聽
listening_test.setEnabled(true);
if (running) {
alarmThread.suspend();
}
running = !running;
}
if (e.getSource() == uploadRing) {
// 上傳文件
}
if (e.getSource() == exit) {
// 退出程序
AlarmFile.exit();
}
if (e.getSource() == screenshot) {
// 主窗體隱藏
iconed = true;
MyAlarm.this.setVisible(false);
// 開始截圖
AlarmTools.screenshot();
}
if (e.getSource() == changeBackground) {
changeBG();
}
if (e.getSource() == about) {
pointX = getMyAlarmX();
pointY = getMyAlarmY();
new AlarmHelp("關於程序");
}
}
/**
* 更改背景圖片</br> 當點擊工具-- >更改背景,這裡就可以處理更改背景圖片
*/
private void changeBG() {
setFlagOfBackground(true);
if (background < AlarmBackground.getBackgroundListSize()) {
iconed = true;
setVisible(false);
if (background != AlarmBackground.getBackgroundListSize() - 1) {
++background;
} else {
background = 0;
}
initMainPanel();
}
}
/**
* 點擊-30按鈕的時候執行的動作
*/
private void minus30Action() {
isHMSZero();
if (dorp_down_minute.getSelectedIndex() - 30 < 0) {
dorp_down_minute.setSelectedIndex(dorp_down_minute
.getSelectedIndex() + 30);// 60-30
if (dorp_down_hours.getSelectedIndex() == 0) {
dorp_down_hours.setSelectedIndex(24);// 設置為23
} else {
// 小時數-1
dorp_down_hours.setSelectedIndex(dorp_down_hours
.getSelectedIndex() - 1);
}
} else {
// 分鐘數-30
dorp_down_minute.setSelectedIndex(dorp_down_minute
.getSelectedIndex() - 30);
}
valueJudgment();
}
/**
* 點擊-5按鈕的時候執行的動作
*/
private void minus5Action() {
isHMSZero();
if (dorp_down_minute.getSelectedIndex() - 5 < 0) {
dorp_down_minute.setSelectedIndex(dorp_down_minute
.getSelectedIndex() + 55);// 60-5
if (dorp_down_hours.getSelectedIndex() == 0) {
dorp_down_hours.setSelectedIndex(24);// 設置為23
} else {
// 小時數-1
dorp_down_hours.setSelectedIndex(dorp_down_hours
.getSelectedIndex() - 1);
}
} else {
// 分鐘數-5
dorp_down_minute.setSelectedIndex(dorp_down_minute
.getSelectedIndex() - 5);
}
valueJudgment();
}
/**
* 點擊-1按鈕的時候執行的動作
*/
private void minus1Action() {
isHMSZero();
if (dorp_down_minute.getSelectedIndex() - 1 == 0) {
dorp_down_minute.setSelectedIndex(60);// 設置為59
if (dorp_down_hours.getSelectedIndex() == 0) {
dorp_down_hours.setSelectedIndex(24);// 設置為23
} else {
// 小時數-1
dorp_down_hours.setSelectedIndex(dorp_down_hours
.getSelectedIndex() - 1);
}
} else {
// 分鐘數-1
dorp_down_minute.setSelectedIndex(dorp_down_minute
.getSelectedIndex() - 1);
}
valueJudgment();
}
/**
* 判斷dorp_down_hours,dorp_down_minute,drop_down_second當前是否為0,即:"關閉"
*/
private void isHMSZero() {
// 如果小時數還沒有設置,那麼就設置為當前小時數
if (dorp_down_hours.getSelectedIndex() == 0) {
dorp_down_hours.setSelectedIndex(getHour() + 1);
}
// 如果分鐘數還沒有設置,那麼就設置為當前分鐘數
if (dorp_down_minute.getSelectedIndex() == 0) {
dorp_down_minute.setSelectedIndex(getMunite() + 1);
}
// 如果秒鐘還沒有設置,那麼就設置為當前秒鐘
if (drop_down_second.getSelectedIndex() == 0) {
drop_down_second.setSelectedIndex(getSecond());
}
}
/**
* 點擊+30按鈕的時候執行的動作
*/
private void add30Action() {
isHMSZero();
if (dorp_down_minute.getSelectedIndex() + 30 > 60) {
dorp_down_minute.setSelectedIndex(dorp_down_minute
.getSelectedIndex() - 30);// +30-60
if (dorp_down_hours.getSelectedIndex() > 23) {
dorp_down_hours.setSelectedIndex(1);// 設置為00
} else {
// 小時數+1
dorp_down_hours.setSelectedIndex(dorp_down_hours
.getSelectedIndex() + 1);
}
} else {
// 分鐘數+30
dorp_down_minute.setSelectedIndex(dorp_down_minute
.getSelectedIndex() + 30);
}
valueJudgment();
}
/**
* 點擊+5按鈕的時候執行的動作
*/
private void add5Action() {
isHMSZero();
if (dorp_down_minute.getSelectedIndex() + 5 > 60) {
dorp_down_minute.setSelectedIndex(dorp_down_minute
.getSelectedIndex() - 55);// +5-60
if (dorp_down_hours.getSelectedIndex() > 23) {
dorp_down_hours.setSelectedIndex(1);// 設置為00
} else {
// 小時數+1
dorp_down_hours.setSelectedIndex(dorp_down_hours
.getSelectedIndex() + 1);
}
} else {
// 分鐘數+5
dorp_down_minute.setSelectedIndex(dorp_down_minute
.getSelectedIndex() + 5);
}
valueJudgment();
}
/**
* 點擊+1按鈕的時候執行的動作
*/
private void add1Action() {
isHMSZero();
if (dorp_down_minute.getSelectedIndex() + 1 > 60) {
dorp_down_minute.setSelectedIndex(1);// 設置為00
if (dorp_down_hours.getSelectedIndex() > 23) {
dorp_down_hours.setSelectedIndex(1);// 設置為00
} else {
// 小時數+1
dorp_down_hours.setSelectedIndex(dorp_down_hours
.getSelectedIndex() + 1);
}
} else {
// 分鐘數+1
dorp_down_minute.setSelectedIndex(dorp_down_minute
.getSelectedIndex() + 1);
}
valueJudgment();
}
/**
* 給h,m,s三個變量賦值,並判斷他們的值
*/
private void valueJudgment() {
h = dorp_down_hours.getSelectedItem().toString();
m = dorp_down_minute.getSelectedItem().toString();
s = drop_down_second.getSelectedItem().toString();
hsmCheck();
}
/**
* 檢查時,分,秒的值,如果都不是"關閉",那麼</br>
*
* <li>stop按鈕要顯示出來</li><br/>
* <li>result要顯示出來剩余時間</li><br/>
* <li>ring_setup要設置為不可用</li> <li>listening_test按鈕為不可用</li> <li>
* listening_test_stop按鈕為不可用</li>
*/
private void hsmCheck() {
if (h != "關閉" && m != "關閉" && s != "關閉") {
stop.setVisible(true);
result.setVisible(true);
ring_setup.setEnabled(false);
listening_test.setEnabled(false);
listening_test_stop.setEnabled(false);
}
}
/**
* stop按鈕的動作: <li>
* 把dorp_down_hours,dorp_down_minute,drop_down_second的值設置為"關閉"</li> <li>
* 隱藏result</li> <li>ring_setup設置為可用</li> <li>listening_test按鈕為可用</li> <li>
* listening_test_stop按鈕為可用</li> <li>stop按鈕設置為不可見</li><li>停止聲音播放</li>
*/
private void stopActionPerformed() {
dorp_down_hours.setSelectedIndex(0);
dorp_down_minute.setSelectedIndex(0);
drop_down_second.setSelectedIndex(0);
result.setVisible(false);
ring_setup.setEnabled(true);
listening_test.setEnabled(true);
listening_test_stop.setEnabled(true);
// 這裡要停止聲音
stop.setVisible(false);
}
/**
* 獲取當前小時數
*
* @return 返回當前小時數
*/
private int getHour() {
return Calendar.getInstance().get(Calendar.HOUR_OF_DAY);
}
/**
* 獲取當前分鐘數
*
* @return 返回當前分鐘數
*/
private int getMunite() {
return Calendar.getInstance().get(Calendar.MINUTE);
}
/**
* 獲取當前秒鐘數
*
* @return 返回當前秒鐘數
*/
private int getSecond() {
return Calendar.getInstance().get(Calendar.SECOND);
}
/**
* 實現震動功能
*/
public void shack() {
Point p = MyAlarm.this.getLocation();
int x = (int) p.getX();
int y = (int) p.getY();
for (int i = 0; i < 5000; i++) {
MyAlarm.this.setLocation(x - 5, y);
MyAlarm.this.setLocation(x, y + 5);
MyAlarm.this.setLocation(x + 5, y);
MyAlarm.this.setLocation(x, y - 5);
}
MyAlarm.this.setLocation(x, y);
}
/**
* 獲取MyAlarm的X坐標
*
* @return 返回MyAlarm的X坐標
*/
public int getMyAlarmX() {
return (int) getLocation().getX();
}
/**
* 獲取MyAlarm的Y坐標
*
* @return 返回MyAlarm的Y坐標
*/
public int getMyAlarmY() {
return (int) MyAlarm.this.getLocation().getY();
}
/**
* 鬧鈴類
*
* @author Hongten
*
* @time 2012-3-2 2012
*/
class AlarmSound implements Runnable {
private String temAlarm;
private String alarm0Path = "src/image/sound/alarm0.wav";//
private String alarm1Path = "src/image/sound/alarm1.wav";//
private String alarm2Path = "src/image/sound/alarm2.wav";//
private String alarm3Path = "src/image/sound/alarm3.wav";//
private String alarm4Path = "src/image/sound/alarm4.wav";//
private String alarm5Path = "src/image/sound/alarm5.wav";//
private String alarm6Path = "src/image/sound/alarm6.wav";//
private String alarm7Path = "src/image/sound/alarm7.wav";//
private String alarm8Path = "src/image/sound/alarm8.wav";//
public AlarmSound(int a) {
switch (a) {
case 0:
temAlarm = alarm0Path;
break;
case 1:
temAlarm = alarm1Path;
break;
case 2:
temAlarm = alarm2Path;
break;
case 3:
temAlarm = alarm3Path;
break;
case 4:
temAlarm = alarm4Path;
break;
case 5:
temAlarm = alarm5Path;
break;
case 6:
temAlarm = alarm6Path;
break;
case 7:
temAlarm = alarm7Path;
break;
case 8:
temAlarm = alarm8Path;
break;
}
}
// 讀取聲音文件,並且播放出來
public void run() {
File soundFile = new File(temAlarm);
AudioInputStream audioInputStream = null;
try {
audioInputStream = AudioSystem.getAudioInputStream(soundFile);
} catch (Exception e1) {
e1.printStackTrace();
return;
}
AudioFormat format = audioInputStream.getFormat();
SourceDataLine auline = null;
DataLine.Info info = new DataLine.Info(SourceDataLine.class, format);
try {
auline = (SourceDataLine) AudioSystem.getLine(info);
auline.open(format);
} catch (Exception e) {
e.printStackTrace();
return;
}
auline.start();
int nBytesRead = 0;
byte[] abData = new byte[512];
try {
while (nBytesRead != -1) {
nBytesRead = audioInputStream
.read(abData, 0, abData.length);
if (nBytesRead >= 0)
auline.write(abData, 0, nBytesRead);
}
} catch (IOException e) {
e.printStackTrace();
return;
} finally {
auline.drain();
auline.close();
}
}
}
}
/Alarm/src/com/b510/ui/main/MyTray.java
代碼如下:
package com.b510.ui.main;
import java.awt.AWTException;
import java.awt.Image;
import java.awt.MenuItem;
import java.awt.PopupMenu;
import java.awt.SystemTray;
import java.awt.TrayIcon;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import com.b510.menu.AlarmFile;
import com.b510.menu.AlarmTools;
public class MyTray implements ActionListener, MouseListener {
private Image icon;// 圖標
private TrayIcon trayIcon;
private SystemTray systemTray;// 系統托盤
private MyAlarm myAlarm; // 托盤所屬主窗體
private PopupMenu pop = new PopupMenu(); // 彈出菜單
// 菜單選項
/** 截圖 */
private MenuItem screenshot = new MenuItem("ScreenShot");
/** 還原 */
private MenuItem open = new MenuItem("Restore");
/** 退出*/
private MenuItem exit =new MenuItem("Exit");
public MyTray(MyAlarm myAlarm) {
this.myAlarm = myAlarm;
// 得到托盤的圖標
icon = new ImageIcon(this.getClass().getClassLoader().getResource(
"image/mytray.png")).getImage();
if (SystemTray.isSupported()) {
systemTray = SystemTray.getSystemTray();
// 設置鼠標經過圖標時,顯示的內容
trayIcon = new TrayIcon(icon, "open Alarm", pop);
pop.add(screenshot);
pop.add(open);
pop.add(exit);
// 添加系統托盤
try {
systemTray.add(trayIcon);
} catch (AWTException e1) {
e1.printStackTrace();
trayIcon.addMouseListener(this);
}
}
displayInfoListener();
trayIcon.addMouseListener(this);
exit.addActionListener(this);
open.addActionListener(this);
screenshot.addActionListener(this);
}
@Override
public void actionPerformed(ActionEvent e) {
if(e.getSource()==exit){
//退出系統
AlarmFile.exit();
}else if (e.getSource() == open) {
// 單點擊菜單中的"還原"選項時,還原窗口
//displayInfo();
//trayIcon.displayMessage("溫馨提示", "hello,world", TrayIcon.MessageType.INFO);
myAlarm.iconed = false;
friendListSet(true);
} else if (e.getSource() == screenshot) {
// 但點擊“截圖”選項時,進行截圖
AlarmTools.screenshot();
}
}
@Override
public void mouseClicked(MouseEvent e) {
// 但鼠標點擊一次的時候,進行彈出窗口
if (e.getClickCount() == 1 && e.getButton() != MouseEvent.BUTTON3) {
if (!myAlarm.isVisible()) {
friendListSet(true);
} else {
friendListSet(false);
}
}
// 但鼠標點擊兩次的時候,進行彈出窗口
// 如果窗口有顯示,則隱藏窗口,否則顯示窗口
if (e.getClickCount() == 2 && e.getButton() != MouseEvent.BUTTON3) {
if (!myAlarm.isVisible()) {
friendListSet(true);
} else {
friendListSet(false);
}
}
}
/**
* 設置friendList的可見性
*/
private void friendListSet(boolean flag) {
myAlarm.setVisible(true);
myAlarm.setExtendedState(JFrame.NORMAL);
}
public void displayInfoListener() {
new Thread(new Runnable() {// 設置一個線程
public void run() {
while (true) {
try {
Thread.sleep(1000);
} catch (Exception e) {
e.printStackTrace();
}
if(myAlarm.getSecondOfResult()==30){
trayIcon.displayMessage("溫馨提示","距鬧鐘設置時間還剩:\n00 時 00 分 " +myAlarm.getSecondOfResult() + " 秒",TrayIcon.MessageType.INFO);
myAlarm.setSecondOfResult(29);
}
if(myAlarm.getFlagOfBackground()){
trayIcon.displayMessage("溫馨提示","您已經更改了背景,點擊托盤圖標\n可以看到效果,右鍵托盤圖標\n可以進行功能選擇。",TrayIcon.MessageType.INFO);
myAlarm.setFlagOfBackground(false);
}
}
}
}).start();
}
@Override
public void mouseEntered(MouseEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void mouseExited(MouseEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void mousePressed(MouseEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void mouseReleased(MouseEvent arg0) {
// TODO Auto-generated method stub
}
}
/Alarm/src/com/b510/ui/up/AlarmShowNow.java
package com.b510.ui.up;
import java.util.Calendar;
/**
*
* @author Hongten
* 主界面區-顯示現在的時間
*/
public class AlarmShowNow {
/**
* 獲得系統的當前時間,並返回
* @return 返回系統當前時間
*/
public static String now() {
Calendar cal = Calendar.getInstance();
int hour = cal.get(Calendar.HOUR_OF_DAY);
int min = cal.get(Calendar.MINUTE);
int sec = cal.get(Calendar.SECOND);
String current = new String(hour+ ":" + min + ":" + sec);
return current;
}
public static void main(String args[]){
System.out.println(now());
}
}
附件下載