2016-08-02 48 views
1

Ich versuche herauszufinden, wie Eingabe Validierung von Textfeld/s zu tun, wenn ich zum Beispiel eine Datumseingabe brauche. Es muss im Format wie 31.8.2016 sein und es muss das heutige Datum oder später sein. Das sind also zwei verschiedene Überprüfungen.JavaFX - TextField Eingabe Validierung mehrerer Anweisungen

Nur so kann ich eine boolesche Methode erstellen, die prüft, ob das Datum Vergangenheit oder Zukunft ist. Aber ich müsste eine neue Methode erstellen, um zu überprüfen, ob es im richtigen Format ist, was schwieriger wird, aber ich denke, das ist nicht der richtige Ansatz.

+0

kann dieser Ihnen helfen => http://stackoverflow.com/questions/28432576/javafx-datepicker-validierung –

+0

Warum habe ich kein Date Picker-Tag in meiner Scene Builder-Bibliothek? – MaraSimo

+0

Welche Version von SceneBuilder haben Sie? –

Antwort

0

Ich schaffe in der Regel ein Datum Klasse, die wie folgt aussieht:

public class Datum {

private boolean validDay = false; 
    private boolean validMonth = false; 
    private boolean validYear = false; 
    private int day; 
    private int month; 
    private int year; 
    private Calendar cal = Calendar.getInstance(); 

    public Date(int day, int month, int year){ 
     /* 
     *All of these conditions can also be individually used to check the conditions you 
     *want to check. simply create 3 texfields and put them in a HBox all values must be entered 
     *separately ! 
     */ 
     if(day>=cal.get(Calendar.DAY_OF_MONTH) && day<=cal.getActualMaximum(Calendar.DAY_OF_MONTH)){ 
      this.day = day; 
      this.validDay = true; 
     } 
     else{ 
      //TODO: handle 
     } 
     if(month>=cal.get(Calendar.MONTH) && month<=12){ 
      this.month = month; 
      this.validMonth= true; 
     } 
     else{ 
      //TODO: handle 
     } 
     if(year>=cal.get(Calendar.YEAR)){ 
      this.year = year; 
      this.validYear = true; 
     } 
     else{ 
      //TODO: handle 
     } 
    } 
    public boolean isDateValid(){ 
     return validDay && validMonth && validYear; 
    } 
    public String getDate(){ 
     return day+"."+month+"."+year; 
    } 
    public int getDay() { 
     return day; 
    } 
    public int getMonth() { 
     return month; 
    } 
    public int getYear() { 
     return year; 
    } 
} 

man konnte den Eingang geteilt mit einem String-Splitter und Kiste Datum! können Sie auch Set-Methoden hinzufügen! gibt es viele Möglichkeiten, dies zu tun! Ich hoffe, das hilft!