繁体   English   中英

当软件在该系统中第一次运行时,如何使用Java显示对话框

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

在我的软件中,当应用程序在该系统中第一次运行时,我想在joptionpane中显示一条消息“ welcome”。 我不想在第二次或更长时间后收到此消息。 当应用程序使用netbeans在该系统中第一次运行时,仅需要一次。

您可以在系统中的某个位置(例如,用户主目录中)创建文件,仅在不存在时创建此文件。

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

您每次使用WindowsListener打开应用程序时都可以运行此代码

这是probaby一个很好的用例

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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