我只是在创建这个特定的,但我对记录这个有点困惑。我只是坚持解释最后几行的作用:
class MyVerifier extends InputVerifier {
public boolean verify(JComponent input) {
if (input==id) {
return validId();
}
else if (input==name) {
return validName();
}
return false;
}
public boolean validId() {
boolean status;
String theID = id.getText();
Pattern pattern = Pattern.compile("\\d{8}");
Matcher matcher = pattern.matcher(theID);
if (matcher.matches()) {
status = true;
}
else {
status = false;
}
return status;
}
public boolean validName() {
boolean status;
String theName = name.getText();
Pattern pattern = Pattern.compile("[A-za-z0-9 ]+");
Matcher matcher = pattern.matcher(theName);
if (matcher.matches()) {
status = true;
}
else {
status = false;
}
return status;
}
}
您能在这里一一解释这些具体的线路吗?
/**
* @param o the object corresponding to the user's selection
*/
@Override
public void tell(Object o) { -- Where has this come from ?
deptCode.setText(o.toString());
}
@Override
public void actionPerformed(ActionEvent e) {
if (e.getSource() == submit) {
MyVerifier test = new MyVerifier();
if (Staff.getStaff(id.getText()) == null && test.verify(id) &&
test.verify(name)) {
System.out.println("YAY");-- What is this doing
}
else if (!(Staff.getStaff(id.getText()) == null)) {
String errorMessage = "ID EXISTS: " + Staff.getStaff(id.getText()).toString(); -- What is this doing
JOptionPane.showMessageDialog(theFrame, errorMessage, "Error",
JOptionPane.WARNING_MESSAGE);-- What is this doing
}
else {
System.out.println("Woops.");
}
}
else if (e.getSource() == clear) {
id.setText(null);
deptCode.setText(null);
name.setText(null);
}
}
public static void main(String[] args) {
Registration test = new Registration();
}
}