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.Frame;

import java.awt.Window;

import javax.swing.SwingUtilities;

public class Main {
    /**
     * Returns the frame that contains the given component.
     *
     * @param component component.
     *
     * @return frame that contains the given component or <code>null</code> if there is
     *         no parent frame.
     */
    public static Frame getOwnerFrame(Component component) {
        Window window = SwingUtilities.windowForComponent(component);
        Frame mother = null;

        if (window != null) {
            Window owner = window.getOwner();

            if ((owner != null) && owner instanceof Frame) {
                mother = (Frame) owner;
            }
        }

        return mother;
    }
}