Java tutorial
import javax.swing.InputVerifier; import javax.swing.JComponent; import javax.swing.JTextField; public class Main { public static void main(String[] args) { JTextField tf = new JTextField(""); tf.setInputVerifier(new MyInputVerifier()); } } class MyInputVerifier extends InputVerifier { public boolean verify(JComponent input) { JTextField tf = (JTextField) input; String pass = tf.getText(); return pass.equals("AA"); } }