0

I want to create a working JTextField that check the input and compare it with a string or an int like: JTextField tf = new JTextField(); if(tf.getText()=="code"){ System.out.println("Code works")} //That doesnt work

It can work with a String or a int but I dont know how can I code it.

  • Hopefully you are just using creating the field and that if on different places. Ofcause a newly created resource is empty. The second issue is that you can not compare strings/objects by `==`. You need to use the `.equals()` method. – LenglBoy Aug 23 '21 at 08:51

0 Answers0