有很多这样的问题,但我已经大致阅读了其中的 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 构建器制作的,它用于类项目,就像我们一样相对较新,它比从头开始构建它要快。