Execute code when exciting the GUI

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Execute code when exciting the GUI

sudheera Navaratne
Hi 

   I have an GIS based agent system running in Repast Simphony using java. When I run the program I get the GUI with my map and all my agents.
   I have some external software executed and running during the run time. I want to exit from this software when I close the GUI. How can I do it.

Thanks
--
Sudheera Navaratne 

------------------------------------------------------------------------------

_______________________________________________
Repast-interest mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/repast-interest
Reply | Threaded
Open this post in threaded view
|

Re: Execute code when exciting the GUI

Tatara, Eric R.
You can add a HierarchyListener to the Repast application frame.  I did a simple static initialization in a ContextBuilder class.  I tried some of the usual WindowListener approaches first, but the Repast application doesn't appear to be passing the window close events to the application frame so WindowListener won't work in this case.  You will need to replace the test println statement below with code necessary to shutdown your external application.

static {
        JFrame frame = RSApplication.getRSApplicationInstance().getGui().getFrame();
       
        frame.addHierarchyListener(new MyHierarchyListener());
    }
   

public class MyHierarchyListener implements HierarchyListener {

    @Override
    public void hierarchyChanged(HierarchyEvent e) {

        if (e.getChangeFlags() == HierarchyEvent.DISPLAYABILITY_CHANGED){
            System.out.println("Repast frame displayability change.");
        }

    }
}


Eric Tatara, PhD, PE
Software Engineer
Global Security Sciences Division
Argonne National Laboratory


From: sudheera Navaratne [[hidden email]]
Sent: Wednesday, October 21, 2015 8:07 AM
To: List, Repast
Subject: [Repast-interest] Execute code when exciting the GUI

Hi 

   I have an GIS based agent system running in Repast Simphony using java. When I run the program I get the GUI with my map and all my agents.
   I have some external software executed and running during the run time. I want to exit from this software when I close the GUI. How can I do it.

Thanks
--
Sudheera Navaratne 

------------------------------------------------------------------------------

_______________________________________________
Repast-interest mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/repast-interest