자바 개발 알 람 구현 코드
효과 그림 1:
효과 그림 2:
효과 도 3:
알 람 에 대하 여:
코드 부분
==========================================================
/Alarm/src/com/b510/main/AlarmMain.java
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/menu/AlarmBackground.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/AlarmFile.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/AlarmHelp.java
package com.b510.menu;
/**
*
* @author Hongten
* -
*/
public class AlarmFile {
/**
*
*/
public static void exit(){
System.exit(0);
}
}
/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 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/ui/main/MyAlarm.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/MyTray.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/up/AlarmShowNow.javapackage 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()); } }첨부 파일 다운로드
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Is Eclipse IDE dying?In 2014 the Eclipse IDE is the leading development environment for Java with a market share of approximately 65%. but ac...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.