I'm quite certain that you'll find there's no way to enumerate the active windows in pure Java (I've looked pretty hard before), so you'll need to code for the platforms you want to target.
On Mac OS X, you can launch an AppleScript using "osascript".
On X11, you can use xwininfo.
On Windows, you can probably launch some VBScript (e.g. this link looks promising).
If you're using SWT, you may be able to find some undocumented, non-public methods in the SWT libs, since SWT provides wrappers for a lot of the OS API's (e.g. SWT on Cocoa has the org.eclipse.swt.internal.cocoa.OS#objc_msgSend()
methods that can be used to access the OS). The equivalent "OS" classes on Windows and X11 may have API's you can use.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…