禁止老师拖堂,禁止老师晚放学

这是大二刚学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();
 }
 
}
 
 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值