-3

I want to find a way to display a notification (like a JOptionpane, a JLabel or any other type) only one time after a user launches my application that is formed in a.jar file.

By only one time, I mean that the user gets a one-time notification after the first use, then for every following times my application runs, this notification should not appear.

My application uses Java Swing. Is there a hint how to make a message pops up from the main JFrame for example?

The Guy with The Hat
  • 10,836
  • 8
  • 57
  • 75
Mike
  • 380
  • 4
  • 19

3 Answers3

1

You simply need to know whether this application has already been running in that environment before or not. A simple way to do that is to:

  • Check whether some file with a particular name exists in the working directory
    • if it doesn't: show your notification, then create the file
    • if it does: don't show your notification

Sample Java code:

private static void notify() {
    final File file = new File(".launched");

    if(!file.exists()) {

        // show your notification HERE

        file.createNewFile();
    }
}
ccjmne
  • 9,333
  • 3
  • 47
  • 62
0
  1. Check for stored value on disk indicating the message has been shown
  2. If not, show the message and store the value on disk.
Charlie
  • 8,530
  • 2
  • 55
  • 53
0

You can do that by setting up one preference. I think is the most straight forward way to do it. Use the preferences class.

The preferences are loaded at starting, then you ask if your "boolean_first_use" is false or true. After that you set it to false, as you know that the user is having that first time message. So next time, it will not fire the notification.

http://www.vogella.com/tutorials/JavaPreferences/article.html

http://www.javaranch.com/journal/2002/10/preferences.html

Sebastian
  • 1
  • 1