Jasper Duizendstra
Jasper Duizendstra

Reputation: 2617

Share a GUI (JFrame) between agent calls

I have a java agents that opens a GUI. When the agent is finished the GUI remains open. Whenever I start the agent again, or start another agent I would like to use the same GUI again.

Is there any way to detect an open GUI or to share the reference between the agents?

Upvotes: 2

Views: 433

Answers (1)

StanislavL
StanislavL

Reputation: 57421

You can use Window class and iterate through all created instances

   /**
     * Returns an array of all {@code Window}s, both owned and ownerless,
     * created by this application.
     * If called from an applet, the array includes only the {@code Window}s
     * accessible by that applet.
     * <p>
     * <b>Warning:</b> this method may return system created windows, such
     * as a print dialog. Applications should not assume the existence of
     * these dialogs, nor should an application assume anything about these
     * dialogs such as component positions, <code>LayoutManager</code>s
     * or serialization.
     *
     * @see Frame#getFrames
     * @see Window#getOwnerlessWindows
     *
     * @since 1.6
     */
public static Window[] getWindows()

also Frame has

public static Frame[] getFrames()

Upvotes: 4

Related Questions