new FileDialog(Frame parent, String title, int mode) : FileDialog « java.awt « Java by API

new FileDialog(Frame parent, String title, int mode)

import java.awt.Button;
import java.awt.FileDialog;
import java.awt.Frame;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class MainClass extends Frame {
  FileDialog fc;

  MainClass() {
    setSize(200, 200);

    fc = new FileDialog(this, "Choose a file", FileDialog.LOAD);

    Button b;
    add(b = new Button("Browse...")); // Create and add a Button
    b.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
        String fn = fc.getFile();
        if (fn == null)
          System.out.println("You cancelled the choice");
          System.out.println("You chose " + fn);

  public static void main(String[] a) {
    new MainClass().setVisible(true);


Related examples in the same category

1.FileDialog: getFile()
2.FileDialog: setDirectory(String dir)