Java tutorial
//package com.java2s; // it under the terms of the GNU General Public License as published by import java.awt.Window; import javax.swing.JDialog; import javax.swing.JFrame; public class Main { /** * Indicates whether the specified window's title contains the given string. * @param window * the window to be checked * @param text * the text to be searched for * @return * true if the window's title contains text, otherwise false */ static boolean titleContains(Window window, String text) { String title = getWindowTitle(window); return (title != null && title.contains(text)); } private static String getWindowTitle(Window window) { String title = null; if (window instanceof JDialog) { title = ((JDialog) window).getTitle(); } else if (window instanceof JFrame) { title = ((JFrame) window).getTitle(); } return title; } }