Ejemplo n.º 1
0
  // constructor initializes LogoAnimatorJPanel by loading images
  public LogoAnimatorJPanel() {
    try {
      // get reference to FileOpenService
      FileOpenService fileOpenService =
          (FileOpenService) ServiceManager.lookup("javax.jnlp.FileOpenService");

      // display dialog that allows user to select multiple files
      FileContents[] contents = fileOpenService.openMultiFileDialog(null, null);

      // create array to store ImageIcon references
      images = new ImageIcon[contents.length];

      // load the selected images
      for (int count = 0; count < images.length; count++) {
        // create byte array to store an image's data
        byte[] imageData = new byte[(int) contents[count].getLength()];

        // get image's data and create image
        contents[count].getInputStream().read(imageData);
        images[count] = new ImageIcon(imageData);
      } // end for

      // this example assumes all images have the same width and height
      width = images[0].getIconWidth(); // get icon width
      height = images[0].getIconHeight(); // get icon height
    } // end try
    catch (Exception e) {
      e.printStackTrace();
    } // end catch
  } // end LogoAnimatorJPanel constructor
Ejemplo n.º 2
0
  public static String getLoadFileName(Frame frame) {

    if (applet != null) {

      showAppletWarning(frame);

      return null;
    }

    String extension = RiskFileFilter.RISK_SAVE_FILES;

    if (webstart != null) {

      try {

        javax.jnlp.FileOpenService fos =
            (javax.jnlp.FileOpenService)
                javax.jnlp.ServiceManager.lookup("javax.jnlp.FileOpenService");

        javax.jnlp.FileContents fc = fos.openFileDialog(SAVES_DIR, new String[] {extension});

        if (fc != null) {

          fileio.put(fc.getName(), fc);

          return fc.getName();
        } else {

          return null;
        }
      } catch (Exception e) {

        return null;
      }
    } else {

      File dir = getSaveGameDir();
      JFileChooser fc = new JFileChooser(dir);

      fc.setFileFilter(new RiskFileFilter(extension));

      int returnVal =
          fc.showDialog(
              frame, TranslationBundle.getBundle().getString("mainmenu.loadgame.loadbutton"));
      if (returnVal == javax.swing.JFileChooser.APPROVE_OPTION) {

        java.io.File file = fc.getSelectedFile();
        // Write your code here what to do with selected file
        return file.getAbsolutePath();

      } else {
        // Write your code here what to do if user has canceled Open dialog
        return null;
      }
    }
  }
Ejemplo n.º 3
0
 private String open() {
   try {
     FileContents fc = fos.openFileDialog(null, null);
     return readFromFile(fc);
   } catch (IOException ioe) {
     ioe.printStackTrace(System.out);
     return null;
   }
 }