2015-11-12 37 views
1

您好,我有一個Java的GUI NetBeans項目當我點擊提交檢查文本框的Java驗證GUI的Netbeans

驗證這裏是我的代碼

private void btnSubmitActionPerformed(java.awt.event.ActionEvent evt) {           


    //VALIDATIONS----------------------------------------------------------- 
    if(txtName.getText().trim().equals("")) 
    { 
     JOptionPane.showMessageDialog(null, "Must have name"); 
     jlblNameVer.setVisible(true); 

    } 
    else 
    { 
     jlblNameVer.setVisible(false); 
    } 

    //ID VERIFICATION 
    if (txtIdNumber.getText().trim().equals("")) 
    { 
     JOptionPane.showMessageDialog(null, "Photo Id must not be emplty"); 
    } 

    //EMAIL VALIDATION 
    if(txtEmail==null ||txtEmail.getText().length() < 10|| txtEmail.getText()== null ||!(txtEmail.getText().trim().contains("@") && txtEmail.getText().trim().contains("."))) 
    { 
     JOptionPane.showMessageDialog(null, "Invalid Email"); 
    } 

    //Phone Number Validation 
    if(txtPhoneNum.getText().length() < 10) 
    { 
     JOptionPane.showMessageDialog(null, "Must atleast 10 characters"); 
    } 

    //COMBOBOX VALIDATIONS 
    if(cmbStayDuration.getSelectedIndex() == -1) 
    { 
     JOptionPane.showMessageDialog(null, "Please select stay duration"); 
    } 

    //Photo ID 
     if(cmbPhotoId.getSelectedIndex() == -1) 
    { 
     JOptionPane.showMessageDialog(null, "Please select Photo ID type"); 
    } 

    String roomType = cmbRoomType.getSelectedItem().toString(); 
    String roomNumber = cmbRoomNumber.getSelectedItem().toString(); 
    String checkin = ftxtCheckinDate.getText(); 
    String checkout = txtCheckOut.getText(); 
    String Name = txtName.getText(); 
    String IdType = cmbPhotoId.getSelectedItem().toString().trim(); 
    String IdNumber = txtIdNumber.getText(); 
    String Phone = txtPhoneNum.getText(); 
    String email = txtEmail.getText().trim(); 


    JOptionPane.showMessageDialog(null,roomType,roomNumber,checkin,checkout,Name,IdType,IdNumber,Phone,email); 

NOT WORKING (optionpane with variables)^^^^^^^^ 


}  

我不會要確保,如果所有這些是正確的,那麼程序有一個彈出窗口,它顯示輸入到窗體中的所有變量。

這裏是GUI http://imgur.com/5nG9jOr

回答

0

JOptionPane的照片不接受這麼多的參數。你應該連接字符串,而不是單獨傳遞它們。

嘗試:

JOptionPane.showMessageDialog(null, "Title", roomType+roomNumber+checkin+checkout+Name+IdType+IdNumber+Phone+email, JOptionPane.OK_OPTION); 
0

你可以傳遞一個數組給選項窗格。在陣列中的每個對象將被顯示在不同的行:

String[] messages = new String[3]; 
messages[0] = "Message line1"; 
messages[1] = "Message line1"; 
messages[2] = "Message line1"; 

JOptionPane.showMessageDialog(
    null, // parent frame 
    messages, 
    "Multiline Message", 
    JOptionPane.INFORMATION_MESSAGE); 

閱讀來自於How to Make Dialog Swing的教程更多實施例和JOptionPane的特徵的部分。