我有一个打开GUI的java代理。代理完成后,GUI保持打开状态。每当我再次启动代理或启动另一个代理时,我想再次使用相同的GUI。
有没有办法检测打开的GUI或在代理之间共享引用?
答案 0 :(得分:4)
您可以使用Window类并遍历所有已创建的实例
/**
* 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()
还有帧
public static Frame[] getFrames()