java.awt.FileDialog.setVisible()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(10.9k)|赞(0)|评价(0)|浏览(153)

本文整理了Java中java.awt.FileDialog.setVisible()方法的一些代码示例,展示了FileDialog.setVisible()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。FileDialog.setVisible()方法的具体详情如下:
包路径:java.awt.FileDialog
类名称:FileDialog
方法名:setVisible

FileDialog.setVisible介绍

暂无

代码示例

代码示例来源:origin: libgdx/libgdx

private File showFileDialog (String title, int mode ) {
  FileDialog dialog = new FileDialog(this, title, mode);
  if (lastDir != null) dialog.setDirectory(lastDir);
  dialog.setVisible(true);
  final String file = dialog.getFile();
  final String dir = dialog.getDirectory();
  if (dir == null || file == null || file.trim().length() == 0) 
    return null;
  lastDir = dir;
  return new File(dir, file);
}

代码示例来源:origin: libgdx/libgdx

private File showFileDialog (String title, int mode ) {
  FileDialog dialog = new FileDialog(this, title, mode);
  if (lastDir != null) dialog.setDirectory(lastDir);
  dialog.setVisible(true);
  final String file = dialog.getFile();
  final String dir = dialog.getDirectory();
  if (dir == null || file == null || file.trim().length() == 0) 
    return null;
  lastDir = dir;
  return new File(dir, file);
}

代码示例来源:origin: libgdx/libgdx

protected void save () {
  FileDialog dialog = new FileDialog(this, "Save Image", FileDialog.SAVE);
  if (lastDir != null) dialog.setDirectory(lastDir);
  dialog.setVisible(true);
  final String file = dialog.getFile();
  final String dir = dialog.getDirectory();
  if (dir == null || file == null || file.trim().length() == 0) return;
  lastDir = dir;
  try {
    generatePremultiplyAlpha(new File(dir, file));
    JOptionPane.showMessageDialog(this, "Conversion complete!");
  } catch (Exception ex) {
    JOptionPane.showMessageDialog(this, "Error saving image.");
    return;
  }
}

代码示例来源:origin: libgdx/libgdx

protected void save () {
  FileDialog dialog = new FileDialog(this, "Save Image", FileDialog.SAVE);
  if (lastDir != null) dialog.setDirectory(lastDir);
  dialog.setVisible(true);
  final String file = dialog.getFile();
  final String dir = dialog.getDirectory();
  if (dir == null || file == null || file.trim().length() == 0) return;
  lastDir = dir;
  try {
    generatePremultiplyAlpha(new File(dir, file));
    JOptionPane.showMessageDialog(this, "Conversion complete!");
  } catch (Exception ex) {
    JOptionPane.showMessageDialog(this, "Error saving image.");
    return;
  }
}

代码示例来源:origin: libgdx/libgdx

public void actionPerformed (ActionEvent evt) {
    FileDialog dialog = new FileDialog(Hiero.this, "Choose TrueType font file", FileDialog.LOAD);
    dialog.setLocationRelativeTo(null);
    dialog.setFile("*.ttf");
    dialog.setDirectory(prefs.get("dir.font", ""));
    dialog.setVisible(true);
    if (dialog.getDirectory() != null) {
      prefs.put("dir.font", dialog.getDirectory());
    }
    String fileName = dialog.getFile();
    if (fileName == null) return;
    fontFileText.setText(new File(dialog.getDirectory(), fileName).getAbsolutePath());
  }
});

代码示例来源:origin: libgdx/libgdx

public void actionPerformed (ActionEvent evt) {
    FileDialog dialog = new FileDialog(Hiero.this, "Choose TrueType font file", FileDialog.LOAD);
    dialog.setLocationRelativeTo(null);
    dialog.setFile("*.ttf");
    dialog.setDirectory(prefs.get("dir.font", ""));
    dialog.setVisible(true);
    if (dialog.getDirectory() != null) {
      prefs.put("dir.font", dialog.getDirectory());
    }
    String fileName = dialog.getFile();
    if (fileName == null) return;
    fontFileText.setText(new File(dialog.getDirectory(), fileName).getAbsolutePath());
  }
});

代码示例来源:origin: libgdx/libgdx

public void actionPerformed (ActionEvent event) {
  FileDialog dialog = new FileDialog(editor, "Select Image", FileDialog.LOAD);
  if (lastDir != null) dialog.setDirectory(lastDir);
  dialog.setVisible(true);
  final String file = dialog.getFile();
  final String dir = dialog.getDirectory();
  if (dir == null || file == null || file.trim().length() == 0) return;
  lastDir = dir;
  try {
    final FileHandle absolute = Gdx.files.absolute(dir + file);
    final BufferedImage read = ImageIO.read(absolute.read());
    final Image scaledInstance = read.getScaledInstance(100, -1, Image.SCALE_SMOOTH);
    final ImageIcon image = new ImageIcon(scaledInstance);
    JLabel previewImage = new JLabel(image);
    previewImage.setOpaque(true);
    previewImage.setBackground(Color.MAGENTA);
    buildImagePanel(previewImage, absolute.file());
  } catch (IOException e) {
    e.printStackTrace();
  }
}

代码示例来源:origin: libgdx/libgdx

public void actionPerformed (ActionEvent event) {
  FileDialog dialog = new FileDialog(editor, "Select Image", FileDialog.LOAD);
  if (lastDir != null) dialog.setDirectory(lastDir);
  dialog.setVisible(true);
  final String file = dialog.getFile();
  final String dir = dialog.getDirectory();
  if (dir == null || file == null || file.trim().length() == 0) return;
  lastDir = dir;
  try {
    final FileHandle absolute = Gdx.files.absolute(dir + file);
    final BufferedImage read = ImageIO.read(absolute.read());
    final Image scaledInstance = read.getScaledInstance(100, -1, Image.SCALE_SMOOTH);
    final ImageIcon image = new ImageIcon(scaledInstance);
    JLabel previewImage = new JLabel(image);
    previewImage.setOpaque(true);
    previewImage.setBackground(Color.MAGENTA);
    buildImagePanel(previewImage, absolute.file());
  } catch (IOException e) {
    e.printStackTrace();
  }
}

代码示例来源:origin: libgdx/libgdx

protected void open () {
  FileDialog dialog = new FileDialog(this, "Open Image", FileDialog.LOAD);
  if (lastDir != null) dialog.setDirectory(lastDir);
  dialog.setVisible(true);
  final String file = dialog.getFile();
  final String dir = dialog.getDirectory();
  if (dir == null || file == null || file.trim().length() == 0) return;
  lastDir = dir;
  try {
    image = ImageIO.read(new File(dir, file));
    imagePanel.setImage(image);
    imagePanel.revalidate();
    imagePanel.repaint();
    pack();
  } catch (Exception ex) {
    JOptionPane.showMessageDialog(this, "Error opening image.");
    return;
  }
}

代码示例来源:origin: libgdx/libgdx

protected void open () {
  FileDialog dialog = new FileDialog(this, "Open Image", FileDialog.LOAD);
  if (lastDir != null) dialog.setDirectory(lastDir);
  dialog.setVisible(true);
  final String file = dialog.getFile();
  final String dir = dialog.getDirectory();
  if (dir == null || file == null || file.trim().length() == 0) return;
  lastDir = dir;
  try {
    image = ImageIO.read(new File(dir, file));
    imagePanel.setImage(image);
    imagePanel.revalidate();
    imagePanel.repaint();
    pack();
  } catch (Exception ex) {
    JOptionPane.showMessageDialog(this, "Error opening image.");
    return;
  }
}

代码示例来源:origin: libgdx/libgdx

public void actionPerformed (ActionEvent evt) {
    FileDialog dialog = new FileDialog(Hiero.this, "Save BMFont files", FileDialog.SAVE);
    dialog.setLocationRelativeTo(null);
    dialog.setFile("*.fnt");
    dialog.setDirectory(prefs.get("dir.savebm", ""));
    if (lastSaveBMFilename.length() > 0) {
      dialog.setFile(lastSaveBMFilename);
    } else if (lastOpenFilename.length() > 0) {
      dialog.setFile(lastOpenFilename.replace(".hiero", ".fnt"));
    }
    dialog.setVisible(true);
    if (dialog.getDirectory() != null) {
      prefs.put("dir.savebm", dialog.getDirectory());
    }
    String fileName = dialog.getFile();
    if (fileName == null) return;
    lastSaveBMFilename = fileName;
    saveBm(new File(dialog.getDirectory(), fileName));
  }
});

代码示例来源:origin: libgdx/libgdx

public void actionPerformed (ActionEvent evt) {
    FileDialog dialog = new FileDialog(Hiero.this, "Save BMFont files", FileDialog.SAVE);
    dialog.setLocationRelativeTo(null);
    dialog.setFile("*.fnt");
    dialog.setDirectory(prefs.get("dir.savebm", ""));
    if (lastSaveBMFilename.length() > 0) {
      dialog.setFile(lastSaveBMFilename);
    } else if (lastOpenFilename.length() > 0) {
      dialog.setFile(lastOpenFilename.replace(".hiero", ".fnt"));
    }
    dialog.setVisible(true);
    if (dialog.getDirectory() != null) {
      prefs.put("dir.savebm", dialog.getDirectory());
    }
    String fileName = dialog.getFile();
    if (fileName == null) return;
    lastSaveBMFilename = fileName;
    saveBm(new File(dialog.getDirectory(), fileName));
  }
});

代码示例来源:origin: libgdx/libgdx

public void actionPerformed (ActionEvent event) {
    FileDialog dialog = new FileDialog(editor, "Open Image", FileDialog.LOAD);
    if (lastDir != null) dialog.setDirectory(lastDir);
    dialog.setVisible(true);
    final String file = dialog.getFile();
    final String dir = dialog.getDirectory();
    if (dir == null || file == null || file.trim().length() == 0) return;
    lastDir = dir;
    final ParticleEmitter emitter = editor.getEmitter();
    emitter.getImagePaths().add(new File(dir, file).getAbsolutePath());
    emitter.getSprites().clear();
    updateImageList(emitter.getImagePaths());
  }
});

代码示例来源:origin: libgdx/libgdx

public void actionPerformed (ActionEvent event) {
    FileDialog dialog = new FileDialog(editor, "Open Image", FileDialog.LOAD);
    if (lastDir != null) dialog.setDirectory(lastDir);
    dialog.setVisible(true);
    final String file = dialog.getFile();
    final String dir = dialog.getDirectory();
    if (dir == null || file == null || file.trim().length() == 0) return;
    lastDir = dir;
    final ParticleEmitter emitter = editor.getEmitter();
    emitter.getImagePaths().add(new File(dir, file).getAbsolutePath());
    emitter.getSprites().clear();
    updateImageList(emitter.getImagePaths());
  }
});

代码示例来源:origin: libgdx/libgdx

public void actionPerformed (ActionEvent evt) {
    FileDialog dialog = new FileDialog(Hiero.this, "Open Hiero settings file", FileDialog.LOAD);
    dialog.setLocationRelativeTo(null);
    dialog.setFile("*.hiero");
    dialog.setDirectory(prefs.get("dir.open", ""));
    dialog.setVisible(true);
    if (dialog.getDirectory() != null) {
      prefs.put("dir.open", dialog.getDirectory());
    }
    String fileName = dialog.getFile();
    if (fileName == null) return;
    lastOpenFilename = fileName;
    open(new File(dialog.getDirectory(), fileName));
  }
});

代码示例来源:origin: libgdx/libgdx

public void actionPerformed (ActionEvent evt) {
    FileDialog dialog = new FileDialog(Hiero.this, "Open Hiero settings file", FileDialog.LOAD);
    dialog.setLocationRelativeTo(null);
    dialog.setFile("*.hiero");
    dialog.setDirectory(prefs.get("dir.open", ""));
    dialog.setVisible(true);
    if (dialog.getDirectory() != null) {
      prefs.put("dir.open", dialog.getDirectory());
    }
    String fileName = dialog.getFile();
    if (fileName == null) return;
    lastOpenFilename = fileName;
    open(new File(dialog.getDirectory(), fileName));
  }
});

代码示例来源:origin: kevin-wayne/algs4

/**
 * Opens a save dialog box when the user selects "Save As" from the menu.
 */
@Override
public void actionPerformed(ActionEvent e) {
  FileDialog chooser = new FileDialog(frame,
             "Use a .png or .jpg extension", FileDialog.SAVE);
  chooser.setVisible(true);
  if (chooser.getFile() != null) {
    save(chooser.getDirectory() + File.separator + chooser.getFile());
  }
}

代码示例来源:origin: kevin-wayne/algs4

/**
 * This method cannot be called directly.
 */
@Override
public void actionPerformed(ActionEvent e) {
  FileDialog chooser = new FileDialog(frame, "Use a .png or .jpg extension", FileDialog.SAVE);
  chooser.setVisible(true);
  String filename = chooser.getFile();
  if (filename != null) {
    save(chooser.getDirectory() + File.separator + chooser.getFile());
  }
}

代码示例来源:origin: kevin-wayne/algs4

/**
 * This method cannot be called directly.
 */
@Override
public void actionPerformed(ActionEvent e) {
  FileDialog chooser = new FileDialog(StdDraw.frame, "Use a .png or .jpg extension", FileDialog.SAVE);
  chooser.setVisible(true);
  String filename = chooser.getFile();
  if (filename != null) {
    StdDraw.save(chooser.getDirectory() + File.separator + chooser.getFile());
  }
}

代码示例来源:origin: kevin-wayne/algs4

/**
 * Opens a save dialog box when the user selects "Save As" from the menu.
 */
@Override
public void actionPerformed(ActionEvent e) {
  FileDialog chooser = new FileDialog(frame,
             "Use a .png or .jpg extension", FileDialog.SAVE);
  chooser.setVisible(true);
  if (chooser.getFile() != null) {
    save(chooser.getDirectory() + File.separator + chooser.getFile());
  }
}

相关文章