How to Find the Parent Frame of a Component Using Java

Frame getParentFrame() {
  Component p = this;

  while ( (p = p.getParent()) != null && !(p instanceof Frame) )
    ;
  return( (Frame)p );
}