I want to know, how to keep a method running in the background. ie. this method starts when the program starts and keeps executing its statements until the program is closed
"SWING isn't thread safe" as you may have seen in may of the Java Docs.
Best way is to use a SwingWorker class. It provides functionality for calculation of results or performance of tasks that have long execution times.