2013-07-22 40 views
-1
private void loadActionPerformed(java.awt.event.ActionEvent evt) {          
     validation(); 
     CreateXml(); 
     clear(); 

    public void validation(){ 
    if (username.getText().trim().length()==0).v{ 

     JOptionPane.showMessageDialog(Retrycount, "Please input user name", "ERROR", JOptionPane.OK_CANCEL_OPTION); 
    } 


    if (PASSWORD1.getText().length()==0){ 

     JOptionPane.showMessageDialog(Retrycount, "Please input password","ERROR", JOptionPane.OK_CANCEL_OPTION); 
    } 
    if(DOMAIN1.getText().length()==0){ 
     JOptionPane.showMessageDialog(Retrycount, "Please input Domain name","ERROR", JOptionPane.OK_CANCEL_OPTION); 

    } 
    if (MYSQLPassword.getText().length() ==0){ 
     JOptionPane.showMessageDialog(Retrycount, "Please input MYSQLPassword","ERROR", JOptionPane.OK_CANCEL_OPTION); 

    } 
    if (Username_Domain.getText().length() ==0){ 
     JOptionPane.showMessageDialog(Retrycount, "Please input second username under FTPFileUploaderPatch","ERROR", JOptionPane.OK_CANCEL_OPTION); 
    } 
    if (Password2.getText().length() ==0){ 
     JOptionPane.showMessageDialog(Retrycount, "Please input Password under FTPFileUploaderPatch","ERROR", JOptionPane.OK_CANCEL_OPTION); 
    } 

    if (DestinationType1.getText().length() ==0){ 
     JOptionPane.showMessageDialog(Retrycount, "Please input DestinationType under FTPFileUploaderPatch","ERROR", JOptionPane.OK_CANCEL_OPTION); 

    } 
    if (DestinationFileName1.getText().length() ==0){ 
     JOptionPane.showMessageDialog(Retrycount, "Please input DestinationFileName under FTPFileUploaderPatch","ERROR", JOptionPane.OK_CANCEL_OPTION);  
    } 

    if (DestinationEntry1.getText().length() ==0){ 
     JOptionPane.showMessageDialog(Retrycount, "Please input DestinationEntry under FTPFileUploaderPatch","ERROR", JOptionPane.OK_CANCEL_OPTION); 

    } 
    if (SubDirectorySearchString1.getText().length() ==0) { 
     JOptionPane.showMessageDialog(Retrycount, "Please input DirectorySearchString under FTPFileUploaderPatch","ERROR", JOptionPane.OK_CANCEL_OPTION); 
    } 
    if (TempDirectory1.getText().length() ==0) { 
     JOptionPane.showMessageDialog(Retrycount, "Please input TempDirectory under FTPFileUploaderPatch","ERROR", JOptionPane.OK_CANCEL_OPTION); 
    } 

    if (SourcePath2.getText().length() ==0) {JOptionPane.showMessageDialog(Retrycount, "Please input SourcePath2 under FTPFileUploaderPatch","ERROR", JOptionPane.OK_CANCEL_OPTION); 

    } 

    if (DestinationType2.getText().length() ==0) { 
     JOptionPane.showMessageDialog(Retrycount, "Please input DestinationType2 under FTPFileUploaderPatch > ReplicationMonitor","ERROR", JOptionPane.OK_CANCEL_OPTION); 
    } 
    if (DestinationType2.getText().length() ==0) { 
     JOptionPane.showMessageDialog(Retrycount, "Please input DestinationPath2 under FTPFileUploaderPatch > ReplicationMonitor","ERROR", JOptionPane.OK_CANCEL_OPTION); 
    } 
    if (DestinationRootFolder2.getText().length() ==0) { 
     JOptionPane.showMessageDialog(Retrycount, "Please input DestinationRootFolder2 under FTPFileUploaderPatch > ReplicationMonitor","ERROR", JOptionPane.OK_CANCEL_OPTION); 
    } 
    if (DestinationFileName2.getText().length() ==0) { 
     JOptionPane.showMessageDialog(Retrycount, "Please input DestinationFileName2 under FTPFileUploaderPatch > ReplicationMonitor","ERROR", JOptionPane.OK_CANCEL_OPTION); 
    } 
    if (DestinationEntry2.getText().length() ==0) { 
     JOptionPane.showMessageDialog(Retrycount, "Please input DestinationEntry2 under FTPFileUploaderPatch > ReplicationMonitor","ERROR", JOptionPane.OK_CANCEL_OPTION); 
    } 
    if (SubDirectorySearchString2.getText().length() ==0) { 
     JOptionPane.showMessageDialog(Retrycount, "Please input SubDirectorySearchString2 under FTPFileUploaderPatch > ReplicationMonitor","ERROR", JOptionPane.OK_CANCEL_OPTION); 
    } 
    if (TempDirectory2.getText().length() ==0) { 
     JOptionPane.showMessageDialog(Retrycount, "Please input TempDirectory2 under FTPFileUploaderPatch > ReplicationMonitor","ERROR", JOptionPane.OK_CANCEL_OPTION); 
    } 
    if (SourcePath3.getText().length() ==0) { 
     JOptionPane.showMessageDialog(Retrycount, "Please input SourcePath3 under FTPFileUploaderPatch > Config.properties","ERROR", JOptionPane.OK_CANCEL_OPTION); 
    } 
    if (DestinationType3.getText().length() ==0) { 
     JOptionPane.showMessageDialog(Retrycount, "Please input DestinationType3 under FTPFileUploaderPatch > Config.properties","ERROR", JOptionPane.OK_CANCEL_OPTION); 
    } 
    if (DestinationPath3.getText().length() ==0) { 
     JOptionPane.showMessageDialog(Retrycount, "Please input DestinationPath3 under FTPFileUploaderPatch > Config.propertiesr","ERROR", JOptionPane.OK_CANCEL_OPTION); 
    } 
    if (DestinationRootFolder3.getText().length() ==0) { 
     JOptionPane.showMessageDialog(Retrycount, "Please input DestinationRootFolder3 under FTPFileUploaderPatch > Config.properties","ERROR", JOptionPane.OK_CANCEL_OPTION); 
    } 
    if (DestinationFileName3.getText().length() ==0) { 
     JOptionPane.showMessageDialog(Retrycount, "Please input DestinationFileName3 under FTPFileUploaderPatch > Config.properties","ERROR", JOptionPane.OK_CANCEL_OPTION); 
    } 
if (DestinationEntry3.getText().length() ==0) { 
     JOptionPane.showMessageDialog(Retrycount, "Please input DestinationEntry3 under FTPFileUploaderPatch > Config.properties","ERROR", JOptionPane.OK_CANCEL_OPTION); 
} 

問題是驗證我需要它,停止第一個文本框之後的驗證並給予注意。如果第一個文本字段爲空,並且您按下了驗證按鈕,則光標應該到達那裏,而不是繼續驗證其餘部分。一次驗證一個字段

如何實現該目標?

+0

請了解共同[爪哇命名約定(http://java.sun.com/docs/books/jls/second_edition/html/names.doc.html#73307)(具體地,用於外殼名稱)用於類,方法和屬性名稱並一致使用它們。 –

+0

'PASSWORD1.getText()'將返回一個'String',這可能會導致安全漏洞。考慮將密碼保存爲'char []'數組,並且一旦完成後使用'Arrays.fill(passwordArray,'')''等內容編寫內容,以便任何人都無法輕鬆訪問它。 –

+0

關於[在Swing窗體驗證過程中繪製警告符號](http://stackoverflow.com/q/14170257/1057230)的此線程可能肯定會讓您感興趣:-) –

回答

3

而是寫

if (PASSWORD1.getText().length()==0){ 
    JOptionPane.showMessageDialog(Retrycount, "Please input password","ERROR", JOptionPane.OK_CANCEL_OPTION); 
} 
if(DOMAIN1.getText().length()==0){ 
    JOptionPane.showMessageDialog(Retrycount, "Please input Domain name","ERROR", JOptionPane.OK_CANCEL_OPTION); 
} 

等的,使用else if建設:

if (PASSWORD1.getText().length()==0){ 
    JOptionPane.showMessageDialog(Retrycount, "Please input password","ERROR", JOptionPane.OK_CANCEL_OPTION); 
} else if(DOMAIN1.getText().length()==0){ 
    JOptionPane.showMessageDialog(Retrycount, "Please input Domain name","ERROR", JOptionPane.OK_CANCEL_OPTION); 
} 
2

後每個字段驗證設置聚焦到現場他們退出的功能。

贊(對函數名稱沒有信心);

if (username.getText().trim().length()==0).v{ 
    JOptionPane.showMessageDialog(Retrycount, "Please input user name", "ERROR", JOptionPane.OK_CANCEL_OPTION); 
    username.getFocus(); 
    return; 
} 
+1

我想你的意思是說[JComponent.requestFocusInWindow( )](http://docs.oracle.com/javase/7/docs/api/javax/swing/JComponent.html#requestFocusInWindow())+1,這種方法也可以工作:-) –

+1

是的,很長一段時間以來我已經完成了Java UI,幸運的是我...... – WattoWatto

相關問題