Java tutorial
//package com.java2s; import java.awt.Component; import java.awt.Container; import java.awt.Frame; public class Main { /** * Finds the Frame containing this component, or null if none found. * @param component the component to search * @return the Frame containing the component */ public static Frame findContainingFrame(Component component) { Container container = component.getParent(); while (container != null && !(container instanceof Frame)) { container = container.getParent(); } return (Frame) container; } }