I have a (Swing + AWT) application which uses an external jar library (by calling a main method inside it). This external application opens a window each time an event occurs (e.g. a button is pressed). Please consider that I have no access to the external jar source code.
How can I close the previously opened window before calling the main again?
The actionPerformed looks like this:
private void anActionPerformed(java.awt.event.ActionEvent evt) {
String [] argv = {"arg1","arg2","arg3"};
com.somepackage.SomeClass.main(argv);
}
You can just guess – which might be wrong – that SomeClass.main calls a Ctor new SomeClass.
You could try to call it yourself:
It it is a JFrame, it is often initialized in main, and some properties are often set:
If that works, you can store the someclass reference in a way, that you later can call
Else you might search every class in the jar:
and use reflection and introspection to search for a ctor to call.
Or you try to extend SomeClass – maybe it isn’t final and can be inherited.