Java tutorial
//package com.java2s; //License from project: Open Source License import java.awt.Window; import javax.swing.JFrame; public class Main { public static JFrame getOnlyVisibleFrame() { JFrame f = null; for (Window w : Window.getWindows()) if (w instanceof JFrame && w.isShowing()) { if (f != null) throw new IllegalStateException("num frames > 1"); f = (JFrame) w; } return f; } }