我用JAVA写了一个WINDOWS保护程序:就是运行执行CMD关机命令,本来在TextFeild
中填入密码后点击确定按钮可以执行取消关机命令,可是怎么调试就是没有,忘大家
帮我看看。对了,我还想问下,怎么可以生成JAR文件后生成可执行文件?(就针对上面的java程序)下面是程序的代码:
//windows密码保护程序
import java.lang.Object;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
public class protectwindows implements ActionListener
{ String str1;
Frame f;
Label l1;
TextField tf1;
Button b1;
Process proc1=null;
public void protectwindows()
{ f=new Frame();
f.setSize(320,350);
f.setLayout(new FlowLayout(FlowLayout.CENTER));
l1=new Label("请输入密码:");
tf1=new TextField();
b1=new Button("确定");
f.add(l1);
f.add(tf1);
f.add(b1);
b1.addActionListener(this);
f.setVisible(true);
f.addWindowListener(new WinClose());
try{
proc1=Runtime.getRuntime().exec("shutdown -s");
} catch(Exception e1){
//e.printStackTrace();
}
}
public void actionPerformed(ActionEvent e)
{ String password="1949101";
str1=(String)(tf1.getText());
if(e.getSource()==b1&&str1==password)
try{
proc1=Runtime.getRuntime().exec("shutdown -a");
} catch(Exception e1){
//e1.printStackTrace();
}
}
public static void main(String args[])
{ protectwindows temp=new protectwindows();
temp.protectwindows();
}
}
class WinClose extends WindowAdapter
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
}
中填入密码后点击确定按钮可以执行取消关机命令,可是怎么调试就是没有,忘大家
帮我看看。对了,我还想问下,怎么可以生成JAR文件后生成可执行文件?(就针对上面的java程序)下面是程序的代码:
//windows密码保护程序
import java.lang.Object;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
public class protectwindows implements ActionListener
{ String str1;
Frame f;
Label l1;
TextField tf1;
Button b1;
Process proc1=null;
public void protectwindows()
{ f=new Frame();
f.setSize(320,350);
f.setLayout(new FlowLayout(FlowLayout.CENTER));
l1=new Label("请输入密码:");
tf1=new TextField();
b1=new Button("确定");
f.add(l1);
f.add(tf1);
f.add(b1);
b1.addActionListener(this);
f.setVisible(true);
f.addWindowListener(new WinClose());
try{
proc1=Runtime.getRuntime().exec("shutdown -s");
} catch(Exception e1){
//e.printStackTrace();
}
}
public void actionPerformed(ActionEvent e)
{ String password="1949101";
str1=(String)(tf1.getText());
if(e.getSource()==b1&&str1==password)
try{
proc1=Runtime.getRuntime().exec("shutdown -a");
} catch(Exception e1){
//e1.printStackTrace();
}
}
public static void main(String args[])
{ protectwindows temp=new protectwindows();
temp.protectwindows();
}
}
class WinClose extends WindowAdapter
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
}
你范了一个初学者最容易范的错误:
if(e.getSource()==b1&&str1==password)
改为:
if(e.getSource()==b1&&str1.equals(password))还有:
temp.protectwindows();//构造函数:public void protectwindows()
import java.lang.Object;//以后不要写了,别人看到了不好看。