Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Open Source License 

import java.awt.Component;

import java.awt.Dialog;
import java.awt.FileDialog;
import java.awt.Frame;
import java.awt.Window;

import javax.swing.SwingUtilities;

public class Main {
    static FileDialog getFileDialog(Component parentComponent) {
        FileDialog dialog;

        Window window = getComponentWindow(parentComponent);
        if (window instanceof Frame) {
            dialog = new FileDialog((Frame) window);
        } else {
            dialog = new FileDialog((Dialog) window);
        }
        return dialog;
    }

    static Window getComponentWindow(Component component) {
        if (component instanceof Window) {
            return (Window) component;
        }
        return SwingUtilities.getWindowAncestor(component);
    }
}