0

有很多这样的问题,但我已经大致阅读了其中的 95% XD 基本上我的代码有一个主类,但它说它没有,这是怎么回事?

public class RegisterGUI extends javax.swing.JFrame {

public RegisterGUI() {
    initComponents();
}

/**
 * This method is called from within the constructor to initialize the form.
 * WARNING: Do NOT modify this code. The content of this method is always
 * regenerated by the Form Editor.
 */
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">                          
private void initComponents() {

    PaySafeTitle = new javax.swing.JLabel();
    TitleLabel = new javax.swing.JLabel();
    FirstNameLabel = new javax.swing.JLabel();
    LastNameLabel = new javax.swing.JLabel();
    EmailAddLabel = new javax.swing.JLabel();
    UsernameLabel = new javax.swing.JLabel();
    PasswordLabel = new javax.swing.JLabel();
    ConfimationLabel = new javax.swing.JLabel();
    TitleList = new javax.swing.JComboBox();
    TitleField = new javax.swing.JTextField();
    FirstNameField = new javax.swing.JTextField();
    LastNameField = new javax.swing.JTextField();
    EmailAddField = new javax.swing.JTextField();
    UsernameField = new javax.swing.JTextField();
    PasswordField = new javax.swing.JPasswordField();
    ConfirmationField = new javax.swing.JPasswordField();
    PasswordMatchLabel = new javax.swing.JLabel();
    MatchResult = new javax.swing.JTextField();
    NextBtn = new javax.swing.JButton();

    setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
    getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

    PaySafeTitle.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
    PaySafeTitle.setIcon(new javax.swing.ImageIcon(getClass().getResource("/PaySafeLogo.png"))); // NOI18N
    getContentPane().add(PaySafeTitle, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 11, 380, 37));

    TitleLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
    TitleLabel.setText("Title:");
    getContentPane().add(TitleLabel, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 54, 98, 23));

    FirstNameLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
    FirstNameLabel.setText("First name:");
    getContentPane().add(FirstNameLabel, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 83, 98, 23));

    LastNameLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
    LastNameLabel.setText("Last name:");
    getContentPane().add(LastNameLabel, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 112, 98, 23));

    EmailAddLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
    EmailAddLabel.setText("Email Address:");
    getContentPane().add(EmailAddLabel, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 141, 98, 23));

    UsernameLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
    UsernameLabel.setText("Username:");
    getContentPane().add(UsernameLabel, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 170, 98, 23));

    PasswordLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
    PasswordLabel.setText("Password:");
    getContentPane().add(PasswordLabel, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 199, 98, 23));

    ConfimationLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
    ConfimationLabel.setText("Confirm Password:");
    getContentPane().add(ConfimationLabel, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 228, 98, 23));

    TitleList.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Mr", "Mrs", "Miss", "Ms", "Dr", "Other..." }));
    getContentPane().add(TitleList, new org.netbeans.lib.awtextra.AbsoluteConstraints(112, 55, 100, -1));

    TitleField.setEditable(false);
    getContentPane().add(TitleField, new org.netbeans.lib.awtextra.AbsoluteConstraints(218, 55, 172, -1));
    getContentPane().add(FirstNameField, new org.netbeans.lib.awtextra.AbsoluteConstraints(112, 84, 278, -1));
    getContentPane().add(LastNameField, new org.netbeans.lib.awtextra.AbsoluteConstraints(112, 113, 278, -1));
    getContentPane().add(EmailAddField, new org.netbeans.lib.awtextra.AbsoluteConstraints(112, 142, 278, -1));
    getContentPane().add(UsernameField, new org.netbeans.lib.awtextra.AbsoluteConstraints(112, 171, 278, -1));

    PasswordField.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            PasswordFieldActionPerformed(evt);
        }
    });
    getContentPane().add(PasswordField, new org.netbeans.lib.awtextra.AbsoluteConstraints(112, 200, 170, -1));
    getContentPane().add(ConfirmationField, new org.netbeans.lib.awtextra.AbsoluteConstraints(112, 229, 170, -1));

    PasswordMatchLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
    PasswordMatchLabel.setText("Password match:");
    getContentPane().add(PasswordMatchLabel, new org.netbeans.lib.awtextra.AbsoluteConstraints(290, 200, 100, 20));

    MatchResult.setEditable(false);
    MatchResult.setHorizontalAlignment(javax.swing.JTextField.CENTER);
    getContentPane().add(MatchResult, new org.netbeans.lib.awtextra.AbsoluteConstraints(290, 230, 100, -1));
    do{
        if((PasswordField.getPassword())==(ConfirmationField.getPassword()));
        MatchResult.setText("MATCH");
    }
    else{
        MatchResult.setText("NO MATCH");
    }
    while((PasswordField.getPassword())!(ConfirmationField.getPassword()));

    NextBtn.setText("Next");
    getContentPane().add(NextBtn, new org.netbeans.lib.awtextra.AbsoluteConstraints(180, 260, -1, -1));

    pack();
}// </editor-fold>                        

private void PasswordFieldActionPerformed(java.awt.event.ActionEvent evt) {                                              
    // 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://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
     */
    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(RegisterGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
    } catch (InstantiationException ex) {
        java.util.logging.Logger.getLogger(RegisterGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
    } catch (IllegalAccessException ex) {
        java.util.logging.Logger.getLogger(RegisterGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
    } catch (javax.swing.UnsupportedLookAndFeelException ex) {
        java.util.logging.Logger.getLogger(RegisterGUI.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 RegisterGUI().setVisible(true);
        }
    });
}
// Variables declaration - do not modify                     
private javax.swing.JLabel ConfimationLabel;
private javax.swing.JPasswordField ConfirmationField;
private javax.swing.JTextField EmailAddField;
private javax.swing.JLabel EmailAddLabel;
private javax.swing.JTextField FirstNameField;
private javax.swing.JLabel FirstNameLabel;
private javax.swing.JTextField LastNameField;
private javax.swing.JLabel LastNameLabel;
private javax.swing.JTextField MatchResult;
private javax.swing.JButton NextBtn;
private javax.swing.JPasswordField PasswordField;
private javax.swing.JLabel PasswordLabel;
private javax.swing.JLabel PasswordMatchLabel;
private javax.swing.JLabel PaySafeTitle;
private javax.swing.JTextField TitleField;
private javax.swing.JLabel TitleLabel;
private javax.swing.JComboBox TitleList;
private javax.swing.JTextField UsernameField;
private javax.swing.JLabel UsernameLabel;
// End of variables declaration                   
}

正如您所看到的那样,大约 3/4 处有一个 main 方法,但 netbeans 似乎没有认识到它的存在:/ 是的,这是使用 GUI 构建器制作的,它用于类项目,就像我们一样相对较新,它比从头开始构建它要快。

4

2 回答 2

2

这一行可能会弄乱解析器:

while((PasswordField.getPassword())!(ConfirmationField.getPassword()));

这是不正确的语法。也许你的意思是:

while((PasswordField.getPassword()) != (ConfirmationField.getPassword()));

虽然语法现在更好,但它在逻辑上仍然不正确。您不能使用!=(或==) 来比较char[]这样的内容;在对象上,这些运算符确定引用是否(或不)指向同一个对象。您将需要另一种方法来比较内容,Arrays.equals(char[], char[]).

此外,您的大括号在您的 do-while 循环中有点偏离。你的代码:

do{
    if((PasswordField.getPassword())==(ConfirmationField.getPassword()));
    MatchResult.setText("MATCH");
}
else{
    MatchResult.setText("NO MATCH");
}
while((PasswordField.getPassword())!(ConfirmationField.getPassword()));

else在这里, matches之前的大括号,do所以你得到else了预期。此外,after条件是不必要且错误的,因为它算作语句体,而不是-- 删除它。ifwhile;ififMatchResult.setText("MATCH")

尝试

do {
    if (Arrays.equals(PasswordField.getPassword(), ConfirmationField.getPassword()))
        MatchResult.setText("MATCH");
    else {
        MatchResult.setText("NO MATCH");
    }
}
while(!Arrays.equals(PasswordField.getPassword(), ConfirmationField.getPassword()));

请注意缩进,这有助于比以前更好地查看大括号的开始和结束位置。

于 2013-08-30T21:05:16.240 回答
0

您可能需要在 IDE 中设置入口点。

于 2013-08-30T21:15:10.190 回答