用Runtime类调用windows程序的问题,感兴趣的朋友请帮忙看看
大家看看源代码:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class test
{
public static void main(String[] args) {
JFrame frame = new JFrame("test");
frame.setSize(new Dimension(400,300));
JButton btn = new JButton("test");
frame.getContentPane().setLayout(new FlowLayout());
frame.getContentPane().add(btn);
btn.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
Runtime rt = Runtime.getRuntime();
String command =
new String("javadoc -d d:\\doc d:\\test.java");
try{
rt.exec(command);
}catch(Exception ex){
ex.printStackTrace();
}
}
});
frame.show();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
在执行javadoc命令时,由于窗口程序和javadoc同时使用一个java虚拟机,因此,点击按钮后javadoc一直处于等待状态,必须关闭窗口才能继续执行,不知道能否让窗口程序和javadoc同时运行?