当类中实际上有一个主方法时,没有主方法



有很多这样的问题,但我已经通读了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的地方有一个主要的方法,但netbeans似乎没有意识到它在那里:/是的,这是使用GUI构建器制作的,它是用于类项目的,因为我们都是相对较新的,所以它比从头开始构建它更快。

这一行可能会扰乱语法分析器:

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

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

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

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

此外,你的牙套在做while循环时会有点脱落。您的代码:

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

这里,else之前的大括号与do匹配,所以您得到的else不需要ifwhile。此外,if条件之后的;是不必要的,也是错误的,因为它算作if语句体,而不是MatchResult.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()));

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

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

相关内容

  • 没有找到相关文章