==========================================================
/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"); // NO 猜你喜欢