我现在用Swing写了一个GUI   然后上面有一个按钮  当我点击这个按钮的时候就打开一个我指定的程序   跟360软件小助手的这个差不多     我想问的是如何得到这个我要打开的程序 路径  然后给ActionLister这个事件   当我点击按钮的时候就调用这个路径的程序  我该怎么写   以前从来没写过  想写着玩下   求高手指教谢谢   

解决方案 »

  1.   

    Process proc = Runtime.getRuntime().exec("notepad.exe");
    打开记事本;
      

  2.   

    Process proc = Runtime.getRuntime().exec("D:/Program Files/PPStream/PPStream.exe"); 
    打开本机上的PPS;
      

  3.   

    public static void main(String[] args) {
    JFrame frame = new JFrame("打开程序");
            FlowLayout flowLayout = new FlowLayout(FlowLayout.CENTER);
            flowLayout.setHgap(20);
            flowLayout.setVgap(20); JButton buttonComfirm = new JButton("打开酷狗");
    buttonComfirm.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    try {
                     Runtime.getRuntime()
    .exec("E:\\Program Files\\YouKu\\iKu\\iKuPlayer.exe");
                    } catch (Exception ex) {
                     ex.printStackTrace();
                    }
                }
            }); frame.add(buttonComfirm);
    frame.setBounds(0, 0, 300, 300);
            frame.setVisible(true);
            frame.setResizable(false);
    }