package testsystray;import java.lang.reflect.*;
import java.util.*;
import java.io.*;
import java.net.*;
import java.rmi.*;/**
 * 流程启动器对象
 * <p>Title: </p>
 * <p>Description: </p>
 * <p>Copyright: Copyright (c) 2003</p>
 * <p>Company: sunyard</p>
 * @author 
 * @version 2.1
 */
public class EngineStartor {
  //类加载器
  private static URLClassLoader ucl = null;  /**
   * 载入指定目录下的所有JAR文件
   * @param path - 存放所有JAR文件的路径
   */
  public static void loadJar(String path1,String path2) throws Exception{
    //参数
    Vector urlVec = new Vector();
    //获得目录
    File libDirectory1 = new File(path1);
    File libDirectory2 = new File(path2);
    if(libDirectory1.isDirectory() && libDirectory2.isDirectory()){
      //列出所有的文件
      String[] fileNames = libDirectory1.list() ;
      String[] fileName = libDirectory2.list() ;
      for(int i=0;i<fileNames.length;i++){
        String postfix = fileNames[i].substring(fileNames[i].length()-3,
                                                fileNames[i].length());
        //判断是否是JAR文件
        if(postfix.equalsIgnoreCase("jar") || postfix.equalsIgnoreCase("zip")){
          String jarFile = "file:" + "/" + path1 + "/" + fileNames[i] + "";
          urlVec.add(jarFile);          //输出被载入的JAR文件
          System.out.println("载入" + jarFile + "...") ;
        }
      }      for(int i=0;i<fileName.length;i++){
        String postfix = fileName[i].substring(fileName[i].length()-3,
                                                fileName[i].length());
        //判断是否是JAR文件
        if(postfix.equalsIgnoreCase("jar") || postfix.equalsIgnoreCase("zip")){
          String jarFile = "file:" + "/" + path2 + "/" + fileName[i] + "";
          urlVec.add(jarFile);          //输出被载入的JAR文件
          System.out.println("载入" + jarFile + "...") ;
        }
      }
      //初始化指向JAR文件的所有URL
      URL[] url = new URL[urlVec.size()];
      for(int i=0;i<url.length ;i++){
        url[i] = new URL((String)urlVec.get(i));
      }      //初始化ClassLoader
      ucl = new URLClassLoader(url,ClassLoader.getSystemClassLoader());
    } else {
      throw new Exception("无效的库文件" );
    }
  }
//启动
  public void loadJarPk()
  {
    try{
      //初始化CLASSLOADER
      System.setProperty("xx","c:\\xx\\Engine");
      //loadJar(System.getProperty("XX_HOME") + File.separator + "lib" + File.separator);
      System.out.println("ucl: " + ucl);
      //启动主程序
      if (ucl != null) {
        Class mainClass = ucl.loadClass("com.sunyard.sunflow.SunflowEngine");        //初始化参数
        Class[] classArray = new Class[1];
        String[] paramArray = new String[1];
        paramArray[0] = new String("Panlei");
        classArray[0] = paramArray.getClass();
        System.out.println("ucl1: ");        //调用MAIN函数
        Method method = mainClass.getMethod("main", classArray);
        System.out.println("ucl2: ");
        method.invoke(null, new Object []{paramArray});
      }
      else {
        System.out.println("无效的类加载器");
      }
    }catch(Exception e){
      e.printStackTrace() ;
    }
  }}

解决方案 »

  1.   

    void addButton( String label )
        {
            JButton btn = new JButton( label );
            btn.setActionCommand( label );
            btn.addActionListener( this );//这个是监听吧?可是别的按钮没有问题,只有这个导入类,然后打开有问题        getContentPane().add( btn );
        }
      

  2.   

    想问一下大家有没有通过BUTTON在后台启一个类似于.BAT文件的,但是没有批处理那个DOS界面,我现在就是通过BUTTON启的,但是启了之后对话框就死了,别的控件就点不了,什么原因?谢谢