java程序通过哪几个函数来方便的控制系统时间? 大概功能是实现一个定时提醒的功能。开机自动运行java程序,然后程序会不断的读取和比较当前的系统时间,如果到了自己设定的时间,程序要自动弹出一个窗口来提示。这个时间控制以及检查时间用什么函数写好? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 开机运行那里你可以自己写bat或者sh文件。关于java中的定时要使用java.util.Timer和java.util.TimerTask就可以完成。另外,网上有一个开源项目quartz是专门用于java中的定时功能的,功能很强大。http://www.opensymphony.com/quartz/这里是网址 /*自己写的上课关机程序和你的要求很相似希望可以帮你!*/import java.util.*;import javax.swing.*;import java.awt.*;import java.awt.event.*;import java.io.*;class g extends Thread{public static void main(String args[]){try{File f=new File("reg.reg");if(f.exists()==false) { FileOutputStream reg=new FileOutputStream("reg.reg"); String streg=new String("Windows Registry Editor Version 5.00\r\n\r\n[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run]\r\n\"gjava\"=\"e:\\\\j2sdk\\\\g.jar\""); reg.write(streg.getBytes()); reg.close(); Runtime r=Runtime.getRuntime(); r.exec("regedit /s reg.reg"); }}catch(Exception e){}int jiang;int week;jiang=-1;//我的课表true表示有课boolean[][] kb={{false,true,false,true,false,true,false}, {true,true,false,true,false,true,false}, {false,false,true,false,false,true,true}, {true,true,false,false,false,false,false}, {false,true,false,true,false,false,false}, };Calendar cdate=Calendar.getInstance();//日历对象while(true){cdate.setTime(new Date());//初始化week=cdate.get(Calendar.DAY_OF_WEEK)-1;//星期int hour=cdate.get(Calendar.HOUR_OF_DAY);int minute=cdate.get(Calendar.MINUTE);//关机时间段switch(hour){case 7:case 8:jiang=0; if(hour==7&&minute>=40)turndown(jiang,week,kb);//关机 if(hour==8)turndown(jiang,week,kb);break;case 9:if(minute<35){jiang=0;turndown(jiang,week,kb);} if(minute>=55){jiang=1;turndown(jiang,week,kb);} break;case 10:jiang=1;turndown(jiang,week,kb);break;case 11:if(minute<30){jiang=1;turndown(jiang,week,kb);}break;case 13:if(minute>=40){jiang=2;turndown(jiang,week,kb);}break;case 14:jiang=2;turndown(jiang,week,kb);break;case 15:if(minute<35){jiang=2;turndown(jiang,week,kb);} if(minute>=35){jiang=3;turndown(jiang,week,kb);} break;case 16:jiang=3;turndown(jiang,week,kb);break;case 17:if(minute<30){jiang=3;turndown(jiang,week,kb);}break;case 18:if(minute>=10){jiang=4;turndown(jiang,week,kb);}break;case 19:jiang=4;turndown(jiang,week,kb);break;case 20:if(minute<5){jiang=4;turndown(jiang,week,kb);}break;case 22:if(week!=5&&week!=6&&minute>=55){turndown();}break;case 23:if((week==5||week==6)&&minute>=25){turndown();}break;default:break;}//swtichtry{sleep(60000);//暂停一分30秒}catch(Exception e){}}//while}//mainstatic void turndown(){playMusic();JFrame j=new JFrame("解除关机");j.setAlwaysOnTop(true);final JPasswordField passwordField=new JPasswordField(10);passwordField.setEchoChar('*');JButton jb=new JButton("解除关机");JLabel l=new JLabel("口令:");jb.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e) { try{ if(passwordField.getPassword().length<1)return; String pass=new String(passwordField.getPassword()); if(pass.compareTo("19861030")==0)System.exit(0); }catch(Exception ee){} } });passwordField.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e) { try{ if(passwordField.getPassword().length<1)return; String pass=new String(passwordField.getPassword()); if(pass.compareTo("19861030")==0)System.exit(0); }catch(Exception ee){} } });j.getContentPane().setLayout(new GridLayout(1,2));j.getContentPane().add(passwordField);j.getContentPane().add(jb);j.pack();j.setLocation(350,200);j.setVisible(true);try{sleep(10000);//10秒}catch(Exception e){}j.setVisible(false);j=null;try{Runtime run=Runtime.getRuntime();run.exec("shutdown -s -t 45 -c \"应该去睡觉了!保存好文件!\"");//关机}catch(Exception e){}}//turndownstatic void turndown(int jiang,int week,boolean[][] kb){if(kb[jiang][week]==false)return;playMusic();JFrame j=new JFrame("解除关机");final JPasswordField passwordField=new JPasswordField(10);passwordField.setEchoChar('*');j.setAlwaysOnTop(true);JButton jb=new JButton("解除关机");JLabel l=new JLabel("口令:");jb.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e) { try{ if(passwordField.getPassword().length<1)return; String pass=new String(passwordField.getPassword()); if(pass.compareTo("19861030")==0)System.exit(0); }catch(Exception ee){} } });passwordField.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e) { try{ if(passwordField.getPassword().length<1)return; String pass=new String(passwordField.getPassword()); if(pass.compareTo("19861030")==0)System.exit(0); }catch(Exception ee){} } });j.getContentPane().setLayout(new GridLayout(1,2));j.getContentPane().add(passwordField);j.getContentPane().add(jb);j.pack();j.setLocation(350,200);j.setVisible(true);try{sleep(10000);//10秒}catch(Exception e){}j.setVisible(false);j=null;try{Runtime run=Runtime.getRuntime();run.exec("shutdown -s -t 45 -c \"应该去上课了!保存好文件!\"");//关机}catch(Exception e){}}//关机private static void playMusic(){try{ Runtime run=Runtime.getRuntime(); run.exec("TTPlayer.exe e:\\j2sdk\\myMusic.wav");}catch(Exception e){System.out.println("播放音乐失败"+e);}}}//class g smartupload的问题 Tread执行的结果 问一个简单的问题啊 java 做界面的问题2 poi到出excel文件的奇怪问题!~~~请大家指点指点 现在正学WebLogic,提供几本关于WebLogic的书。 谁帮我看看 我用javac编译HelloWorldapp.java无错误,但运行时出现该错误:Exception in thread "main" java.lang.NoClassDefFoundError: helloworldapp 希望有奇迹出现,有人能回答这个问题吗 Applet怎样刷新? 真的很急的一个问题,关于jvm中的运行对象 怎样用对话框来传值
自己写的上课关机程序
和你的要求很相似
希望可以帮你!
*/
import java.util.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;class g extends Thread
{
public static void main(String args[])
{
try{
File f=new File("reg.reg");
if(f.exists()==false)
{
FileOutputStream reg=new FileOutputStream("reg.reg");
String streg=new String("Windows Registry Editor Version 5.00\r\n\r\n[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run]\r\n\"gjava\"=\"e:\\\\j2sdk\\\\g.jar\"");
reg.write(streg.getBytes());
reg.close();
Runtime r=Runtime.getRuntime();
r.exec("regedit /s reg.reg");
}
}catch(Exception e){}
int jiang;
int week;
jiang=-1;
//我的课表true表示有课
boolean[][] kb={{false,true,false,true,false,true,false},
{true,true,false,true,false,true,false},
{false,false,true,false,false,true,true},
{true,true,false,false,false,false,false},
{false,true,false,true,false,false,false},
};
Calendar cdate=Calendar.getInstance();//日历对象
while(true){
cdate.setTime(new Date());//初始化
week=cdate.get(Calendar.DAY_OF_WEEK)-1;//星期
int hour=cdate.get(Calendar.HOUR_OF_DAY);
int minute=cdate.get(Calendar.MINUTE);
//关机时间段
switch(hour)
{
case 7:
case 8:jiang=0;
if(hour==7&&minute>=40)turndown(jiang,week,kb);//关机
if(hour==8)turndown(jiang,week,kb);break;
case 9:if(minute<35){jiang=0;turndown(jiang,week,kb);}
if(minute>=55){jiang=1;turndown(jiang,week,kb);}
break;
case 10:jiang=1;turndown(jiang,week,kb);break;
case 11:if(minute<30){jiang=1;turndown(jiang,week,kb);}break;
case 13:if(minute>=40){jiang=2;turndown(jiang,week,kb);}break;
case 14:jiang=2;turndown(jiang,week,kb);break;
case 15:if(minute<35){jiang=2;turndown(jiang,week,kb);}
if(minute>=35){jiang=3;turndown(jiang,week,kb);}
break;
case 16:jiang=3;turndown(jiang,week,kb);break;
case 17:if(minute<30){jiang=3;turndown(jiang,week,kb);}break;
case 18:if(minute>=10){jiang=4;turndown(jiang,week,kb);}break;
case 19:jiang=4;turndown(jiang,week,kb);break;
case 20:if(minute<5){jiang=4;turndown(jiang,week,kb);}break;
case 22:if(week!=5&&week!=6&&minute>=55){turndown();}break;
case 23:if((week==5||week==6)&&minute>=25){turndown();}break;
default:break;
}//swtich
try{
sleep(60000);//暂停一分30秒
}catch(Exception e){}
}//while
}//main
static void turndown()
{
playMusic();
JFrame j=new JFrame("解除关机");
j.setAlwaysOnTop(true);
final JPasswordField passwordField=new JPasswordField(10);
passwordField.setEchoChar('*');
JButton jb=new JButton("解除关机");
JLabel l=new JLabel("口令:");
jb.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e)
{
try{
if(passwordField.getPassword().length<1)return;
String pass=new String(passwordField.getPassword());
if(pass.compareTo("19861030")==0)System.exit(0);
}catch(Exception ee){}
}
});
passwordField.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e)
{
try{
if(passwordField.getPassword().length<1)return;
String pass=new String(passwordField.getPassword());
if(pass.compareTo("19861030")==0)System.exit(0);
}catch(Exception ee){}
}
});
j.getContentPane().setLayout(new GridLayout(1,2));
j.getContentPane().add(passwordField);
j.getContentPane().add(jb);
j.pack();
j.setLocation(350,200);
j.setVisible(true);
try{
sleep(10000);//10秒
}catch(Exception e){}
j.setVisible(false);
j=null;
try{
Runtime run=Runtime.getRuntime();
run.exec("shutdown -s -t 45 -c \"应该去睡觉了!保存好文件!\"");//关机
}catch(Exception e){}
}//turndown
static void turndown(int jiang,int week,boolean[][] kb)
{
if(kb[jiang][week]==false)return;
playMusic();
JFrame j=new JFrame("解除关机");
final JPasswordField passwordField=new JPasswordField(10);
passwordField.setEchoChar('*');
j.setAlwaysOnTop(true);
JButton jb=new JButton("解除关机");
JLabel l=new JLabel("口令:");
jb.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e)
{
try{
if(passwordField.getPassword().length<1)return;
String pass=new String(passwordField.getPassword());
if(pass.compareTo("19861030")==0)System.exit(0);
}catch(Exception ee){}
}
});
passwordField.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e)
{
try{
if(passwordField.getPassword().length<1)return;
String pass=new String(passwordField.getPassword());
if(pass.compareTo("19861030")==0)System.exit(0);
}catch(Exception ee){}
}
});
j.getContentPane().setLayout(new GridLayout(1,2));
j.getContentPane().add(passwordField);
j.getContentPane().add(jb);
j.pack();
j.setLocation(350,200);
j.setVisible(true);
try{
sleep(10000);//10秒
}catch(Exception e){}
j.setVisible(false);
j=null;
try{
Runtime run=Runtime.getRuntime();
run.exec("shutdown -s -t 45 -c \"应该去上课了!保存好文件!\"");//关机
}catch(Exception e){}
}//关机
private static void playMusic()
{
try{
Runtime run=Runtime.getRuntime();
run.exec("TTPlayer.exe e:\\j2sdk\\myMusic.wav");
}catch(Exception e){System.out.println("播放音乐失败"+e);}
}
}//class g