当前位置: 技术问答>java相关
如何用Applet调用EXECLE文件
来源: 互联网 发布时间:2015-01-19
本文导语: 我想用APPLET调用execle程序,并将数据库的值取出,并在execle上显示,并打印OK | Try the following applet code, after filling in the Runtime.exec the exact adress where your local application is located. If your ru...
我想用APPLET调用execle程序,并将数据库的值取出,并在execle上显示,并打印OK
|
Try the following applet code, after filling in the Runtime.exec the exact adress where your local application is located. If your running in a windows OS, please note that you must enter \ instead of (example: c:\winnt\notepad.exe)
And due, to security reason, you must make one of the following things too:
1) you must sign your applet (I don't know how to do that) 2) or you save the applet into a folder that is declared in your classpath (I know how to do it in winNt):
(1.- execute sysedit (before programs menu))
2.- write into Autoexec.bat the following code:
SET PATH=%PATH%;%JAVAHOME%BIN
SET CLASSPATH=.;C:jdk1.1.8lib;C:jdk1.1.8
bin;C:jdk1.1.8class; (this is my example. I save all my applets into C:jdk1.1.8class)
3.- save autoexec.bat
4.- restart your computer
And the applet it now supposed to work succesfully. I hope this help you
best Regards,
Pisonero
import java.io.*;
import java.applet.*;
import java.awt.*;
import java.net.*;
import java.awt.event.*;
public class interfaz4okartes extends Applet implements MouseListener {
Graphics g;
boolean estado;
public void init() {
Button boton = new Button("Lanzar Aplicacion");
add(boton);
boton.addMouseListener(this);
estado = false;
}
public void destroy() {
removeMouseListener(this);
}
public void mouseClicked(MouseEvent event) {
if (estado == false){
try {
Runtime.getRuntime().exec("c:\where your application is located.exe");
g.drawString("Success executing Application", 10, 10);
}
catch (SecurityException e) {
g.drawString("Caught security exception trying to run an underlying program", 10, 10);
}
catch (IOException ioe) {
g.drawString("Caught i/o exception in exec", 10, 10);
}
estado = true;
}
else
return;
}
public void mousePressed(MouseEvent event) {}
public void mouseReleased(MouseEvent event) {}
public void mouseEntered(MouseEvent event) {}
public void mouseExited(MouseEvent event) {}
}
And due, to security reason, you must make one of the following things too:
1) you must sign your applet (I don't know how to do that) 2) or you save the applet into a folder that is declared in your classpath (I know how to do it in winNt):
(1.- execute sysedit (before programs menu))
2.- write into Autoexec.bat the following code:
SET PATH=%PATH%;%JAVAHOME%BIN
SET CLASSPATH=.;C:jdk1.1.8lib;C:jdk1.1.8
bin;C:jdk1.1.8class; (this is my example. I save all my applets into C:jdk1.1.8class)
3.- save autoexec.bat
4.- restart your computer
And the applet it now supposed to work succesfully. I hope this help you
best Regards,
Pisonero
import java.io.*;
import java.applet.*;
import java.awt.*;
import java.net.*;
import java.awt.event.*;
public class interfaz4okartes extends Applet implements MouseListener {
Graphics g;
boolean estado;
public void init() {
Button boton = new Button("Lanzar Aplicacion");
add(boton);
boton.addMouseListener(this);
estado = false;
}
public void destroy() {
removeMouseListener(this);
}
public void mouseClicked(MouseEvent event) {
if (estado == false){
try {
Runtime.getRuntime().exec("c:\where your application is located.exe");
g.drawString("Success executing Application", 10, 10);
}
catch (SecurityException e) {
g.drawString("Caught security exception trying to run an underlying program", 10, 10);
}
catch (IOException ioe) {
g.drawString("Caught i/o exception in exec", 10, 10);
}
estado = true;
}
else
return;
}
public void mousePressed(MouseEvent event) {}
public void mouseReleased(MouseEvent event) {}
public void mouseEntered(MouseEvent event) {}
public void mouseExited(MouseEvent event) {}
}