securityapplet.java
来自「java网络高级编程的配套源码,java网络高级编程为清华出版社出版.」· Java 代码 · 共 98 行
JAVA
98 行
/*源程序清单12-15*/
package safe;
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import borland.jbcl.layout.*;
import borland.jbcl.control.*;
import java.lang.Runtime;
import netscape.security.PrivilegeManager;
public class SecurityApplet extends Applet
{
XYLayout xYLayout1 = new XYLayout();
boolean isStandalone = false;
GroupBox groupBox1 = new GroupBox();
TextField textField1 = new TextField();
Button button1 = new Button();
XYLayout xYLayout2 = new XYLayout();
//Construct the applet
public SecurityApplet()
{
}
//Initialize the applet
public void init()
{
try
{
jbInit();
}
catch (Exception e)
{
e.printStackTrace();
}
}
//Component initialization
private void jbInit() throws Exception
{
xYLayout1.setWidth(400);
xYLayout1.setHeight(300);
groupBox1.setLayout(xYLayout2);
groupBox1.setLabel("请输入程序路径及名称:");
button1.setLabel("启动");
button1.addActionListener(new SecurityApplet_button1_actionAdapter(this));
this.setLayout(xYLayout1);
this.add(groupBox1, new XYConstraints(21, 15, 348, 68));
groupBox1.add(textField1, new XYConstraints(15, 5, 232, -1));
groupBox1.add(button1, new XYConstraints(256, 6, 61, -1));
}
//Get Applet information
public String getAppletInfo()
{
return "Applet Information";
}
//Get parameter info
public String[][] getParameterInfo()
{
return null;
}
void button1_actionPerformed(ActionEvent e)
{
PrivilegeManager.enablePrivilege("UniversalExecAccess");
try
{
String pathname=textField1.getText();
Runtime runtime=Runtime.getRuntime();
runtime.exec(pathname);
}catch(Exception ee)
{
MessageDialog mdlg=new MessageDialog(new Frame(),"错误","请确认你所输入的程序路径是否正确?",1);
mdlg.show();
}
}
}
class SecurityApplet_button1_actionAdapter implements java.awt.event.ActionListener
{
SecurityApplet adaptee;
SecurityApplet_button1_actionAdapter(SecurityApplet adaptee)
{
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e)
{
adaptee.button1_actionPerformed(e);
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?