java - Implement clearing prefilled fields/ check if answer is correct -
i want change followingmethod thelastname field not pre filled , checks in private boolean isinputvalid if entered value equal thelastname field. @ moment field pre filled , checks if field empty or not. how should code looks 2 changes?
package ch.makery.address.view; import javafx.fxml.fxml; import javafx.scene.control.textfield; import javafx.stage.stage; import org.controlsfx.dialog.dialogs; import ch.makery.address.model.person; /** * dialog train word. * * */ public class englishtraindialogcontroller { @fxml private textfield firstnamefield; @fxml private textfield lastnamefield; @fxml private stage dialogstage; private person person; private boolean okclicked = false; /** * initializes controller class. method automatically called * after fxml file has been loaded. */ @fxml private void initialize() { } /** * sets stage of dialog. * * @param dialogstage */ public void setdialogstage(stage dialogstage) { this.dialogstage = dialogstage; } /** * sets person edited in dialog. * * @param person */ public void setperson(person person) { this.person = person; firstnamefield.settext(person.getfirstname()); lastnamefield.settext(person.getsecondenglish()); } /** * returns true if user clicked ok, false otherwise. * * @return */ public boolean isokclicked() { return okclicked; } /** * called when user clicks check , go back. */ @fxml private void handleok() { if (isinputvalid()) { person.setfirstname(firstnamefield.gettext()); person.setlastname(lastnamefield.gettext()); okclicked = true; dialogstage.close(); } } /** * called when user clicks cancel. */ @fxml private void handlecancel() { dialogstage.close(); } /** * validates user input in text fields. * * @return true if input valid */ private boolean isinputvalid() { string errormessage = ""; if (firstnamefield.gettext() == null || firstnamefield.gettext().length() == 0) { errormessage += "no valid german word!\n"; } if (lastnamefield.gettext() == null || lastnamefield.gettext().length() == 0) { errormessage += "no valid english word!\n"; } if (errormessage.length() == 0) { return true; } else { // show error message. dialogs.create() .title("wrong spelling") .masthead("please correct!") .message(errormessage) .showerror(); return false; } } }
Comments
Post a Comment