2016-05-24 2 views
0

Ich versuche zu überprüfen, ob die Eingabe eines Benutzers in ein Textfeld bestimmte Buchstaben enthält, und es einen Zähler erhöhen, wenn es tut.Wie überprüfen Sie, ob ein Textfeld in einer GUI etwas enthält?

//this is the code for the button 
//tfYourName is the name of the text field 
//below is what I've tried already 
private void btnResultsMouseClicked(java.awt.event.MouseEvent evt) { 
    if (tfYourName.getSelectedItems.toString.toUpperCase().contains("T")) 
} 
+1

Und was ist Ihre Frage? – Tom

+0

@Tom Wahrscheinlich, warum es nicht kompiliert, da es nicht so kompilieren wird. :-) – Vampire

+0

[Text von TextField abrufen] (http://StackOverflow.com/a/31260653/452708) – Abhijeet

Antwort

0
if (tfYourName.getText().toUpperCase().contains("T")) 
    counter++; 
+0

"// mehr Code hier" sollte wahrscheinlich 'counter ++;' sein :) – Yev

+0

Ja, wusste einfach nicht Was war das? Ich kann es ändern – RobotKarel314