dimanche 6 décembre 2015

java if else errors not working properly

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

if (compName==null){JOptionPane.showMessageDialog(new JFrame(), "Company Name required", "Error", JOptionPane.ERROR_MESSAGE);} else{ if(regNo==null){JOptionPane.showMessageDialog(new JFrame(), "Registration number required", "Error", JOptionPane.ERROR_MESSAGE);} else{ if(addressL1==null){JOptionPane.showMessageDialog(new JFrame(), "Address required", "Error", JOptionPane.ERROR_MESSAGE);} else{ if(postcode==null){JOptionPane.showMessageDialog(new JFrame(), "postcode required", "Error", JOptionPane.ERROR_MESSAGE);} else { if(username==null){JOptionPane.showMessageDialog(new JFrame(), "Username required", "Error", JOptionPane.ERROR_MESSAGE);} else{ if(password==null){JOptionPane.showMessageDialog(new JFrame(), "Password required", "Error", JOptionPane.ERROR_MESSAGE);} else{ BufferedWriter output; try { File user = new File(username.getText()+".txt"); output = new BufferedWriter(new FileWriter(user)); output.write(compName.getText()); output.append(System.lineSeparator()); output.write(regNo.getText()); output.append(System.lineSeparator()); output.write((String) Day.getSelectedItem()+(String) Month.getSelectedItem()+(String) Year.getSelectedItem()); output.append(System.lineSeparator()); output.write(addressL1.getText()+addressL3.getText()+addressL3.getText()); output.append(System.lineSeparator()); output.write(postcode.getText()); output.append(System.lineSeparator()); output.write(email.getText()); output.append(System.lineSeparator()); output.write(mobile.getText()); output.append(System.lineSeparator()); output.write(username.getText()); output.append(System.lineSeparator()); output.write(password.getText()); output.append(System.lineSeparator()); output.close(); } catch ( IOException IOe ) {

                     }
                     dispose();       // TODO add your handling code here:
                 }
             }
         }
     }
 }

} }

/**
 * @param args the command line arguments
 */
public static void main(String args[]) {
    /* Set the Nimbus look and feel */
    //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
    /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
     * For details see http://ift.tt/1cNmMj1 
     */
    try {
        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(regcomp.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
    } catch (InstantiationException ex) {
        java.util.logging.Logger.getLogger(regcomp.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
    } catch (IllegalAccessException ex) {
        java.util.logging.Logger.getLogger(regcomp.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
    } catch (javax.swing.UnsupportedLookAndFeelException ex) {
        java.util.logging.Logger.getLogger(regcomp.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
    }
    //</editor-fold>

    /* Create and display the form */
    java.awt.EventQueue.invokeLater(new Runnable() {
        public void run() {
            new regcomp().setVisible(true);
        }
    });
}

// Variables declaration - do not modify                     
private javax.swing.JComboBox Day;
private javax.swing.JComboBox Month;
private javax.swing.JComboBox Year;
private javax.swing.JTextField addressL1;
private javax.swing.JTextField addressL2;
private javax.swing.JTextField addressL3;
private javax.swing.JLabel addressLabel1;
private javax.swing.JLabel addressLabel2;
private javax.swing.JLabel addressLabel3;
private javax.swing.JTextField compName;
private javax.swing.JLabel companyLabel;
private javax.swing.JTextField email;
private javax.swing.JLabel emailLabel;
private javax.swing.JTextField mobile;
private javax.swing.JLabel mobileLabel;
private javax.swing.JTextField password;
private javax.swing.JLabel passwordLabel;
private javax.swing.JTextField postcode;
private javax.swing.JLabel postcodeLabel;
private javax.swing.JLabel regDateLabel;
private javax.swing.JTextField regNo;
private javax.swing.JLabel regNoLabel;
private javax.swing.JButton register;
private javax.swing.JTextField username;
private javax.swing.JLabel usernameLabel;
// End of variables declaration                   

}

Aucun commentaire:

Enregistrer un commentaire