简体   繁体   中英

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

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 .

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

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);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM