这是大二刚学Java的时候写的了,主要原因是那个老师老师说上一级得多厉害,还会在电脑里设置按时关机,我就很差异,那也叫厉害,所以谢了这个程序,把它装在了教室得电脑里,设置成自启动,它主要实现了按时提醒下课并播放10分钟音乐,然后提醒上课,最后放学按时关机 找了好久才找出来的,可能现在看很简单了,但是还是拿来纪念一下吧,高手不要说我,师弟们也不要去乱用 有喜欢JAva和Android的可以交流 群:
150086842
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Font;
import java.util.*;
import java.text.*;
import javax.swing.JFrame;
import javax.swing.JLabel;
public class music{
Font f =new Font("黑体",1,15);
static String message = null;
public music(){
JFrame frame = new JFrame("友情提示");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(600,150);
frame.setLocation(600,300);
frame.setBackground(Color.blue);
frame.setLayout(new BorderLayout());
frame.getContentPane();
frame.setAlwaysOnTop(true);
frame.getContentPane().setBackground(Color.cyan);
JLabel l1 = new JLabel(message);
l1.setFont(f);
frame.getContentPane().add(l1);
frame.setVisible(true); //弹出消息窗口
try{
Thread.sleep(5000); //消息窗口停留5秒钟
}catch(Exception e){
}
frame.setVisible(false); //消息窗口隐藏,此处不能用System.exit(0);语句否则程序全部会被终止
}
public static void main(String[] args){
boolean f =true;
Runtime run = Runtime.getRuntime();
String str2= "8:48:00";
String str3 = "9:48:00";
String str4 = "10:48:00";
String str5 = "11:45:00";
String str6 = "15:18:00";
String str7 = "16:18:00";
String str8 = "17:15:00";
String str9 = "11:50:00";
String str10 = "17:20:00";
Process process1=null;
playThread p = new playThread ();
while(f) {
Date date = new Date();
DateFormat d1 = DateFormat.getTimeInstance();
String str = d1.format(date);
if((boolean)str.equals(str2)||(boolean)str.equals(str3)||(boolean)str.equals(str4)||(boolean)str.equals(str6)||(boolean)str.equals(str7)){
message=" 老师您讲课时间久了会累的,休息一下吧,为你播放十分钟的音乐放松一下";
new Thread(p).start();
new music();
}
else if((boolean)str.equals(str5)||(boolean)str.equals(str8)){
message= " 还有五分钟关机,希望老师总结一下,祝老师天天开心,谢谢";
new music();
}
else if((boolean)str.equals(str9)||(boolean)str.equals(str10)){
try{
process1 = run.exec("shutdown /s /t 0");
}catch(Exception e1){
System.out.println("It is wrong");
}
}
else {
try{
Thread.sleep(1000);//为了让线程挂起,来释放CPU,否则CPU的使用率会100%
}catch(Exception e){
}
}
}
}
}
class playThread implements Runnable
{
public void run()
{
Process process=null;
Runtime run = Runtime.getRuntime();
try{
process=run.exec("\"D:/Program Files/QQMusic/QQMusic.exe\"");
}catch(Exception e){
}
try{
Thread.sleep(600000);
}catch(Exception e){
}
process.destroy();
}
}