Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import java.awt.Component;

import java.awt.Dialog;

import java.awt.Frame;

import java.awt.HeadlessException;

import java.awt.Window;

public class Main {
    /**
     * Returns the parent window for the component by navigating up the
     * component hierarchy. 
     *
     * @param comp the component to test.
     * @return the parent {@link Window} if one is found.
     * @throws HeadlessException
     */
    public static Window getWindowForComponent(Component comp) throws HeadlessException {
        if (comp instanceof Frame || comp instanceof Dialog) {
            return (Window) comp;
        }
        return getWindowForComponent(comp.getParent());
    }
}