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

import javax.swing.JFrame;

public class Main {
    /**
     * Returns the parent <code>JFrame</code> of the specified component.
     * 
     * @param component the component to find the parent JFrame for.
     * @return the parent JFrame.
     */
    public static JFrame getParentJFrame(Component component) {
        if ((component == null) || (component instanceof JFrame)) {
            return (JFrame) component;
        }
        Container c = component.getParent();
        while ((c != null) && !(c instanceof JFrame)) {
            c = c.getParent();
        }
        return (JFrame) c;
    }
}