2011-12-21 84 views
0

我有一個應用程序,我用鼠標在pc上運行,我想從java中啓動具有特定文件名的edrawingsviewer,然後當用戶返回到全屏應用程序時,如果它們沒有關閉它我想關閉它。這是我迄今爲止的快速演示,但我無法弄清楚爲了用特定文件啓動solidworks而在參數中輸入什麼內容。從java打開edrawingsviewer文件

package com.protocase.hmiclient.edrawings; 

import java.awt.event.ActionEvent; 
import java.awt.event.ActionListener; 
import java.io.File; 
import java.io.FilenameFilter; 
import java.io.IOException; 
import javax.swing.JButton; 
import javax.swing.JFrame; 

/** 
* @author DavidH 
*/ 
public class EDrawingHelper { 

    public static File[] getEDrawingsForJob(final String jobNumber) { 
     File f = new File("\\\\itsugar\\www\\HMI\\POD EDRAWINGS"); 
     File[] matchingFiles = f.listFiles(new FilenameFilter() { 
      public boolean accept(File dir, String name) { 
       return name.startsWith(jobNumber) && (name.endsWith("EASM") || name.endsWith("EDRW")); 
      } 
     }); 
     return matchingFiles; 
    } 
    public static void test(String[] args) { 
     File[] files = getEDrawingsForJob("G080111004-13162-1"); 
     for (File file : files){ 
      System.out.println(file.getName()); 
     } 
    } 
    public static void openEDrawingForFileName(String fileName){ 
     try { 
      final Process process = Runtime.getRuntime().exec("C:\\Program Files\\SolidWorks Corp\\SolidWorks eDrawings (2)\\EModelViewer.exe \\\\itsugar\\www\\HMI\\POD EDRAWINGS\\"+fileName); 
      JFrame frame = new JFrame(); 
      JButton killButton = new JButton("KILL"); 
      killButton.addActionListener(new ActionListener() { 
       @Override 
       public void actionPerformed(ActionEvent e) { 
        process.destroy(); 
        System.exit(0); 
       } 
      }); 
      frame.getContentPane().add(killButton); 
      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 
      frame.pack(); 
      frame.setVisible(true); 
     } catch (IOException e) { 
      e.printStackTrace(); 
     } 
    } 
    public static void main(String[] args) { 
     openEDrawingForFileName("G080111004-13162-1 ASSEMBLY.EASM"); 
    } 
} 

我不認爲這是一個solidworks問題,我認爲這只是我通過錯誤或格式錯誤或什麼的東西。

回答

0

它看起來好像是通過FileProtocolHandler運行它導致它打開罰款。

final Process process = Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler \\\\itsugar\\www\\HMI\\POD EDRAWINGS\\"+fileName);