I made a simple application that automatically uploads/downloads files to and from a server given that there are files to upload or download. I am using a Timer Task to periodically check if there are files locally to upload, or files online to download.
Everything is working fine, and I decided that every time that there is a successful upload/download, I'll show a message dialogue to show the user that a file was successfully uploaded/downloaded.
So far, this is what I have, I am calling this function infoBox
. Note that I am doing this in the TimerTask
:
public static void infoBox(String infoMessage, String titleBar){
Toolkit.getDefaultToolkit().beep();
JOptionPane.showMessageDialog(null, infoMessage, titleBar,
JOptionPane.INFORMATION_MESSAGE);
}
Then based on whether or not I got a file or I sent a file, I call it as such:
infoBox("Files Sent!", "Files were sent successfully!");
Or
infoBox("Files Received!", "Files were downloaded successfully!");
And it works fine. If I get a file from the server, or upload a file to it, the message pops up fine.
However, it seems that the TimerTask stops whenever it shows the message dialogue. I have to click "Ok" for the dialogue to close and for the TimerTask to do its thing again.
What I want to happen is for the TimerTask to execute over and over again, regardless how many message dialogues it has shown.
I have a feeling I misplaced where I declared and called my infoBox
function. Is there a way for a programs routine task to continually execute as I show message dialogues?