簡體   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