How to show a dialog box a software using java when the software run 1st time in that system

182 views Asked by At

In my software I want to show a message "welcome " in joptionpane when the application run 1st time in that system. I do not want this message in 2nd or any more time. Only required in once when the application run 1st time in that system using netbeans .

2

There are 2 answers

0
VGR On BEST ANSWER

This is probaby a good use case for Preferences:

Preferences prefs = Preferences.userNodeForPackage(getClass());
boolean hasRunBefore = prefs.getBoolean("hasRunBefore", false);
if (!hasRunBefore) {
    prefs.putBoolean("hasRunBefore", true);

    JOptionPane.showMessageDialog(mainWindow,
        "Welcome to ExampleApp!", "Welcome",
        JOptionPane.INFORMATION_MESSAGE,
        applicationIcon);
}
2
richersoon On

You can create a file in somewhere in system (for example in user home directory), only create this file if not exist.

File file = new File(System.getProperty("user.dir") +"/.launch_first_time");

if(!file.exist()) {
file.createNewFile();
  JOptionPane.showMessageDialog (null, "welcome", "Launch for the first time", JOptionPane.INFORMATION_MESSAGE);
}

You can run this code everytime you open the application using WindowsListener