My java code is trying to create a if statement based on if the individual line of the text area object is filled or not. My code works when there is nothining in the text area box however as soon as a character is entered the if text is empty does not work anymore.As you can see in the gif. When a character is entered and the user hits enter even though the line has nothing on it. Sam is still added to the line. That should not happen. Sam should be only added to the line if character is on the line.
public void keyPressed(KeyEvent e) {
if(e.getKeyCode() == KeyEvent.VK_ENTER){
if(text11.jt.getText().trim().isEmpty()) {
System.out.println( "Hi" );
}
else {
text11.jt.setText(text11.jt.getText() + " sam");
}
}
}
Aucun commentaire:
Enregistrer un commentaire