2014-07-06 35 views
1

我在Java動態應用程序中有以下JForm,我需要下載一些我不想在GUI中顯示的文件,我希望程序通過命令行運行。我們可以在DOS模式下啓動Java Jframe程序

我們可以使用相同的形式嗎?或者我們需要爲它創建一個單獨的桌面應用程序?

這裏是代碼..

public class LoginForm extends javax.swing.JFrame 
    { 

    \\some other code 

    \\ main function of form 

    /** 
    * @param args the command line arguments 
    */ 
     public static void main(String args[]) { 
     try { 
      if(args.length > 0) 
      { 
       setGuiDisplay(1); 
       for (String s: args) { 
        System.out.println(s); 
       } 
      } 
      else 
      { 

      for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) { 
       if ("Nimbus".equals(info.getName())) { 
        javax.swing.UIManager.setLookAndFeel(info.getClassName()); 
        break; 
       } 
      } 
      } 
     } catch (ClassNotFoundException ex) { 
      java.util.logging.Logger.getLogger(LoginForm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); 
     } catch (InstantiationException ex) { 
      java.util.logging.Logger.getLogger(LoginForm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); 
     } catch (IllegalAccessException ex) { 
      java.util.logging.Logger.getLogger(LoginForm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); 
     } catch (javax.swing.UnsupportedLookAndFeelException ex) { 
      java.util.logging.Logger.getLogger(LoginForm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); 
     } 

    public static void setGuiDisplay(int GuiDisplay) { 
     LoginForm.GuiDisplay = GuiDisplay; 

     //Start Downloading 
     FrmMain frm1= new FrmMain(); 
     frm1.StartDownload(); 
    } 
+0

問題很好,但我想知道爲什麼你需要在CUI基於GUI的應用程序?如果你明確我的疑問,我會很高興。 – gprathour

+0

@GPRathour我想下載沒有用戶粘貼的文件,你提到XML文件並下載它。 – javadotnetcoder

回答

0

是的,它是可能的,從來不叫setVisible(true),當沒有GUI代碼與下載混合,這樣的錯誤消息。可能是進度動畫已完成,但沒有效果,只要沒有顯示。

這是更多的重構問題,從GUI分離下載;這是有道理的。對於其他搜索者:Java也可以無頭安裝,即:一些沒有GUI的linux系統,就像一些簡約的服務器一樣。 There有人可能會遇到問題。

+0

嗨@joop感謝您的回答,是否可以顯示下載狀態20%,..? – javadotnetcoder

+0

你的意思是經常出現的「10%」backspace³「11%」等等。從來沒聽說過。 –

+0

你建議爲它建立2個獨立的應用程序? – javadotnetcoder

0

當然你可以下載東西到你的Swing應用程序中。你需要讓這個進程在單獨的線程中運行。

看看SwingWorker。該組件將幫助您設計一個與GUI操作並行運行的線程。或者,如果在下載後不需要在GUI中顯示任何內容,則可以使用標準線程。

+0

感謝您的解釋,但就像我想在DOS模式下顯示10%完整的消息,我該如何實現它 – javadotnetcoder

相關問題