日期:2014-05-20  浏览次数:20841 次

如何用java实现程序开机自动运行?
如何用java实现程序开机自动运行?

------解决方案--------------------
期待答案!
------解决方案--------------------
上课时间自动关机程序!
package 管理;
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\ "=\ "javaw g\ " ");
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={{true,false,true,true,true,false,false},
{false,false,true,true,true,false,false},
{true,false,true,false,true,false,false},
{true,false,true,false,false,false,false},
{true,false,true,false,true,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()
{
JFrame j=new JFrame( "解除关机 ");
final JPasswordField passwordField=new JPasswordField(10);
passwordField.setEchoChar( '0 ');
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);