0
我開發銀行應用驗證一個ID號碼的方法。這是一個學校任務(Java系統開發),這是我的第一年,我仍然是一個新手。我需要幫助的方法的目的是根據不同的細節驗證ID號碼。創建,根據某些具體
我已經使用這個code的一部分,但修改了它。現在,當我將ID號碼寫入文本框時,什麼也沒有發生。我正在使用卡片佈局。該方法位於「註冊」面板上。這個想法是,如果ID號碼(和密碼)是正確的,應該能夠在下一個面板上登錄。
我爲控制檯開發的代碼,但我試圖讓它與jFrame一起工作。我認爲這在瑞典是一個很常見的學校任務,我不認爲說更多的學生可能會使用我可能會在這裏得到的幫助是徒勞的。
public class BankFrame extends javax.swing.JFrame {
public BankFrame() {
initComponents();
} //This is the method that I have problems with:
private void registerBtnActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
Register customer = new Register(password);
if (password.equals("")){
outReg.setText("Enter a password as required.");
}
}
void CorrectId() {
//panel
}
public void CorrectId(String id) {
if (validateNumbers(id)) {
RegPanel.setVisible(false); // I am using CardLayout. This method is in the RegPanel.
LoginPanel.setVisible(true); //This shoul allow the user to change to the Login panel if the id is valideted by the method.
base.removeAll();
base.add(LoginPanel);
revalidate();
repaint();
} else {
outReg.setText("Enter a valid ID-number before proceeding");
while (true) {
id = (regIdIn.getText());
id = id.replaceAll("-", "").trim(); // A swedish ID number looks like this 890123-0000. I have to remove - to be able to run the method validateNumbers.
if (id.equals("")) { // A warning that should be written on the outReg label.
outReg.setText("Enter your id as required.");
break;
}
}
}
}
public boolean validateNumbers(String nm) { //new String so that "id" keeps it's values.
int numberSize = nm.length();
if (numberSize != 10) { // Warning if the ID-number has too little or too many numbers.
outReg.setText("Only 10 numbers is allowed!");
return false;
} else if (nm.matches("\\d+")) {
return true;
} else { //Warning if there is letters in the ID-number.
outReg.setText("You are kidding... I hope! ");
return false;
}
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
}
}
你有沒有叫correctId()的任何地方,我認爲應該在registerBtnActionPerformed – Gaur93
被稱爲謝謝!我按照你的建議編輯了代碼。問題的一部分解決了,但程序一直工作到縮進。 –
你還沒有在任何地方調用correctId – Gaur93