考勤提示软件源代码

package checkDuty;

import java.awt.Color;
import java.awt.Container;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.net.InetAddress;
import java.util.Calendar;
import java.util.Date;

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.Timer;
import javax.swing.WindowConstants;


public class KaoQing1 {
   
    private static int convertSecond;
    private static int amOnDutyStart;
    private static int amOnDutyEnd;
    private static int amOffDutyStart;
    private static int amOffDutyEnd;
    private static int pmOnDutyStart;
    private static int pmOnDutyEnd;
    private  static int pmOffDutyStart;
    private static int pmOffDutyEnd;
    private static boolean AM_ON_DUTY;
    private  static boolean AM_OFF_DUTY;
    private static boolean PM_ON_DUTY;
    private static boolean PM_OFF_DUTY;
    private static int currHour, currMinute, currSecond;
    private static Container contentPane;
    private static JLabel timeLabel;
    private static Color colors;
   
    private static Runtime rt;
    private static String command1;
    private static String command2;
    private static String machineName;  //here is ip
//    private String userName;
    public  KaoQing1(){
//          6:00-8:30 12:00-13:00 13:00-13:30 18:00-20:00 
        amOnDutyStart = convertSecond( 6 );
        amOnDutyEnd = convertSecond( 8, 35, 0 ); //可做测试用
       
        amOffDutyStart = convertSecond( 12 );
        amOffDutyEnd = convertSecond( 13, 00, 0 );
       
        pmOnDutyStart = convertSecond( 13, 00, 5 );
        pmOnDutyEnd = convertSecond( 13, 30, 0 );
        pmOffDutyStart = convertSecond( 18 );
        pmOffDutyEnd = convertSecond( 20 );
        AM_ON_DUTY = false;
        AM_OFF_DUTY = false;
        PM_ON_DUTY = false;
        PM_OFF_DUTY = false;
        GetIP getIP = new GetIP();
//        userName = getIP.getUserName();
        machineName = getIP.getMachineName();
        command1 = "net send " + machineName + " 考勤时间到了!请考勤!";
//        System.out.println( command1 );
        command2 = "explorer http://192.168.1.82/login/crm_login.htm ";
//        command = "";
        rt = Runtime.getRuntime();
       
    }
   
    public static void main( String args[]){
        JFrame jframe = new JFrame( "poloyzhang@126.com ");
        jframe.setUndecorated(true);
//        jframe.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
        jframe.setDefaultCloseOperation( WindowConstants.EXIT_ON_CLOSE );
//        jframe.setDefaultCloseOperation( WindowConstants.DO_NOTHING_ON_CLOSE );
        contentPane = jframe.getContentPane();
        JLabel currTimeLabel = new JLabel();
        currTimeLabel.setFont( new Font("Serif", Font.BOLD, 12 ) );
        currTimeLabel.setText( "Current time is: ");
        timeLabel = new JLabel("", JLabel.CENTER );
        timeLabel.setFont( new Font("Serif", Font.ITALIC, 12) );
        FlowLayout flowlayout = new FlowLayout( FlowLayout.LEFT,6, 5 );
        contentPane.setLayout( flowlayout );
        contentPane.add( currTimeLabel );
        contentPane.add( timeLabel );
        colors = new Color(255, 128, 64);
        contentPane.setBackground( colors );
        ActionListener listener = new ActionListener( ){
//          6:00-8:30 12:00-13:30 13:00-13:30 18:00-20:00 
           
            public void actionPerformed( ActionEvent e ){
                Calendar cal = Calendar.getInstance();
                Date dates = cal.getTime();
                currHour = dates.getHours();
                currMinute = dates.getMinutes();
                currSecond = dates.getSeconds();
                int convertCurSecond = convertSecond( currHour, currMinute, currSecond);
               
                if( convertCurSecond > amOnDutyStart &&
                    convertCurSecond < amOnDutyEnd && AM_ON_DUTY == false ){
                    try{
                        rt.exec( command1 );
                        JOptionPane.showMessageDialog( contentPane, " 现在为上午上班时间," +
                                            "请考勤,现在时间为: "  + dates.toLocaleString() );
                        rt.exec( command2 );
                    }catch( Exception es ){
                        es.printStackTrace();
                    }
                   
                    AM_ON_DUTY = true;
                }
                else if( convertCurSecond > amOffDutyStart &&
                        convertCurSecond < amOffDutyEnd && AM_OFF_DUTY == false ){
                      
                    AM_OFF_DUTY = true;
                       
                        try{
                            rt.exec( command1 );
                            JOptionPane.showMessageDialog( contentPane, " 现在为上午下班时间," +
                                     "请考勤,现在时间为: "  + dates.toLocaleString() );
                           
                            rt.exec( command2 );
                        }catch( Exception es ){
                            es.printStackTrace();
                        }
                       
                }
                else if( convertCurSecond > pmOnDutyStart &&
                        convertCurSecond < pmOnDutyEnd && PM_ON_DUTY == false ){
                       
                        PM_ON_DUTY = true;
                       
                        try{
                            rt.exec( command1 );
                            JOptionPane.showMessageDialog( contentPane,  " 现在为下午上班时间," +
                                    "请考勤,现在时间为: "  + dates.toLocaleString() );
                            rt.exec( command2 );
                        }catch( Exception es ){
                            es.printStackTrace();
                        }
                       
                 }
                else if( convertCurSecond > pmOffDutyStart &&
                        convertCurSecond < pmOffDutyEnd && PM_OFF_DUTY == false ){
                      
                        PM_OFF_DUTY = true;
                       
                        try{
                            rt.exec( command1 );
                             JOptionPane.showMessageDialog( contentPane,  " 现在为下午下班时间," +
                                     "请考勤,现在时间为: "   + dates.toLocaleString() );
                            rt.exec( command2 );
                        }catch( Exception es ){
                            es.printStackTrace();
                        }
                }
                timeLabel.setText( dates.toLocaleString() );
//                contentPane.repaint();
                contentPane.repaint();
//                System.out.println( dates.toLocaleString() );
            }
        };
       
        KaoQing1 kq = new KaoQing1();
       
        Timer timer = new Timer( 1000, listener );
        timer.start();
        jframe.setResizable(false);
        jframe.setSize( 250,25 );
        jframe.setLocation( 450, 0 );
        jframe.show();
    }
public static int convertSecond(int hour, int minute, int second ){
    convertSecond = hour * 3600 + minute * 60 + second;
    return convertSecond;
}
public int convertSecond( int hour ){
    convertSecond = hour * 3600;
    return convertSecond;
}

}
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值