您好,我有一個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