예제 #1
0
 public Set<String> listResources(String subdir) {
   try {
     Set<String> result = new HashSet<String>();
     if (resourceURL != null) {
       String protocol = resourceURL.getProtocol();
       if (protocol.equals("jar")) {
         String resPath = resourceURL.getPath();
         int pling = resPath.lastIndexOf("!");
         URL jarURL = new URL(resPath.substring(0, pling));
         String resDirInJar = resPath.substring(pling + 2);
         String prefix = resDirInJar + subdir + "/";
         // System.out.printf("BaseMod.listResources: looking for names starting with %s\n",
         // prefix);
         JarFile jar = new JarFile(new File(jarURL.toURI()));
         Enumeration<JarEntry> entries = jar.entries();
         while (entries.hasMoreElements()) {
           String name = entries.nextElement().getName();
           if (name.startsWith(prefix) && !name.endsWith("/") && !name.contains("/.")) {
             // System.out.printf("BaseMod.listResources: name = %s\n", name);
             result.add(name.substring(prefix.length()));
           }
         }
       } else throw new RuntimeException("Resource URL protocol " + protocol + " not supported");
     }
     return result;
   } catch (Exception e) {
     throw new RuntimeException(e);
   }
 }
예제 #2
0
  public AppFrame() {
    super();
    GlobalData.oFrame = this;
    this.setSize(this.width, this.height);
    this.toolkit = Toolkit.getDefaultToolkit();

    Dimension w = toolkit.getScreenSize();
    int fx = (int) w.getWidth();
    int fy = (int) w.getHeight();

    int wx = (fx - this.width) / 2;
    int wy = (fy - this.getHeight()) / 2;

    setLocation(wx, wy);

    this.tracker = new MediaTracker(this);
    String sHost = "";
    try {

      localAddr = InetAddress.getLocalHost();
      if (localAddr.isLoopbackAddress()) {
        localAddr = LinuxInetAddress.getLocalHost();
      }
      sHost = localAddr.getHostAddress();
    } catch (UnknownHostException ex) {
      sHost = "你的IP地址错误";
    }
    //
    this.textLines[0] = "服务器正在运行.";
    this.textLines[1] = "";
    this.textLines[2] = "你的IP地址: " + sHost;
    this.textLines[3] = "";
    this.textLines[4] = "请打开你的手机客户端";
    this.textLines[5] = "";
    this.textLines[6] = "输入屏幕上显示的IP地址.";
    //
    try {
      URL fileURL = this.getClass().getProtectionDomain().getCodeSource().getLocation();
      String sBase = fileURL.toString();
      if ("jar".equals(sBase.substring(sBase.length() - 3, sBase.length()))) {
        jar = new JarFile(new File(fileURL.toURI()));

      } else {
        basePath = System.getProperty("user.dir") + "\\res\\";
      }
    } catch (Exception ex) {
      this.textLines[1] = "exception: " + ex.toString();
    }
  }