本地调用
来源:互联网 发布:吉林大学网络教育 官网 编辑:程序博客网 时间:2024/05/01 23:23
本程序是一个调用本地windows中的一些命令实现的,原理很easy,只是使用了Runtime.getRuntime().exec,程序中的那些调用都可以System32中找到,对于用户自己安装的程序,只需取得程序的安装路径,再调用上面那个方法实现就可以了,原理是一样的。(本程序没有实现,不想写了,原理都一样)
源码:
LocalEXE.java
package LocalEXE;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
public class LocalEXE {
private JFrame mainF;
private DefaultListModel LModel = new DefaultListModel();
private JMenuItem infoMI;
public LocalEXE() {
mainF = new JFrame();
mainF.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
addMenu();
loadInfo();
createList();
showFrame();
}
private void addMenu() {
JMenuBar mainMB = new JMenuBar();
mainF.setJMenuBar(mainMB);
JMenu helpM = new JMenu("Help");
mainMB.add(helpM);
infoMI = new JMenuItem("Info");
infoMI.addActionListener(new MenuL());
helpM.add(infoMI);
}
private void showFrame() {
mainF.setTitle("LocalEXE");
mainF.setSize(500,400);
mainF.setResizable(false);
mainF.setLocation(200,100);
mainF.setVisible(true);
}
private void loadInfo() {
EXEInterface ExeI;
String name, address;
name = new String("计算器");
address = new String("calc.exe");
ExeI = new EXEInterface(name, address);
LModel.addElement(ExeI);
name = new String("接龙");
address = new String("freecell.exe");
ExeI = new EXEInterface(name, address);
LModel.addElement(ExeI);
name = new String("媒体播放器");
address = new String("mplay32.exe");
ExeI = new EXEInterface(name, address);
LModel.addElement(ExeI);
name = new String("红心大战");
address = new String("mshearts.exe");
ExeI = new EXEInterface(name, address);
LModel.addElement(ExeI);
name = new String("画图工具");
address = new String("mspaint.exe");
ExeI = new EXEInterface(name, address);
LModel.addElement(ExeI);
name = new String("记事本");
address = new String("NotePad.exe");
ExeI = new EXEInterface(name, address);
LModel.addElement(ExeI);
name = new String("扫雷");
address = new String("winmine.exe");
ExeI = new EXEInterface(name, address);
LModel.addElement(ExeI);
name = new String("注册表");
address = new String("regedt32.exe");
ExeI = new EXEInterface(name, address);
LModel.addElement(ExeI);
}
private void createList() {
final JList sList = new JList(LModel);
final JTextArea sTA = new JTextArea(8,15);
JSplitPane sPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,
new JScrollPane(sList), new JScrollPane(sTA));
sPane.setBackground(Color.WHITE);
sPane.setContinuousLayout(true);
sPane.setOneTouchExpandable(true);
mainF.getContentPane().add(sPane);
sList.addListSelectionListener(new ListSelectionListener() {
int executeTime = 0;
public void valueChanged(ListSelectionEvent event) {
EXEInterface value = (EXEInterface)sList.getSelectedValue();
if(value != null) {
executeTime++;
System.out.println(executeTime);
if(executeTime % 2 == 0) {
sTA.setText("");
sTA.setText("System Load " + value.getName());
try {
Process subP = Runtime.getRuntime().exec(value.getAddress());
}catch(Exception e) {
System.out.println("Runtime exe Error!");
sTA.setText("Runtime exe Error!");
e.printStackTrace();
}
}
}
if(executeTime == 10)
executeTime = 0;
}
});
}
class MenuL implements ActionListener {
public void actionPerformed(ActionEvent e) {
Object command = e.getSource();
if(command == infoMI) {
infoDlg();
}
}
public void infoDlg() {
JPanel msgP = new JPanel();
msgP.setLayout(new GridLayout(3, 1));
msgP.add(new JLabel("Author : pluto"));
msgP.add(new JLabel("Date : 2005.4"));
msgP.add(new JLabel("Site : BJTU15#"));
JOptionPane.showMessageDialog(null, msgP, "Info", JOptionPane.YES_OPTION);
}
}
public static void main(String[] args) {
new LocalEXE();
}
}
EXEInterface.java
package LocalEXE;
class EXEInterface {
private String name, address;
public EXEInterface(String name, String address) {
this.name = name;
this.address = address;
}
public String getName() {
return name;
}
public String getAddress() {
return address;
}
public String toString() {
return name;
}
}
- 本地调用
- 本地调用, “本地调用”和远程调用!
- javascript调用本地exe
- SWT调用本地API
- java调用本地命令
- java 调用本地命令
- java调用本地程序
- JavaScript调用本地命令
- javascript调用本地程序
- 调用本地程序
- Flex 调用本地应用程序
- JAVA调用本地方法
- 本地调用google地图
- java 调用本地应用程序
- swf调用本地程序
- UIWebView调用本地
- Ruby 调用本地程序
- js调用本地exe
- 成为软件高手的几个忌讳(转贴)
- 是不是应该去北京?
- 程序人生
- 喜 欢 和 爱 的 区 别
- 不错,请多多关照!
- 本地调用
- 学生成绩管理系统
- 计算机语言
- .NET 源代码的安全性(源代码工具真正比拼) (論)(3)
- 身体是革命的本钱 - 颈椎病预防
- 一个罕为人知的无敌命令 几乎清除所有进程
- 回来我的爱
- 颈椎病预防
- 办公室人员颈椎病预防