Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import java.awt.Frame;

import java.util.ArrayList;

import java.util.List;

public class Main {
    /**
     * Returns the first found frame of {@code #findFramesWithIcons()}. <p> Especially for usage in a
     * <code>JOptionPane#show...Dialog()</code> instead of null. Then in the dialog frame an icon will be displayed that
     * is different to the Java "coffee cup" icon.
     *
     * @return frame or null
     */
    public static Frame findFrameWithIcon() {
        List<Frame> frames = findFramesWithIcons();

        return (frames.isEmpty()) ? null : frames.get(0);
    }

    /**
     * Finds frames with an icon: Frames of {@code Frame#getFrames()} where
     * {@code Frame#getIconImage()} returns not null.
     *
     * @return frames with an icon or an empty list
     */
    public static List<Frame> findFramesWithIcons() {
        List<Frame> frames = new ArrayList<>();
        Frame[] allFrames = Frame.getFrames();

        for (Frame frame : allFrames) {
            if (frame.getIconImage() != null) {
                frames.add(frame);
            }
        }

        return frames;
    }
}