Skip to content
Advertisement

how to use JTextField to show a negative or positive result using ActionListener on the JTextField itself

My program is supposed to ask a user to write a number in a JTextField and then show the result if the number is negative or positive in another JTextField that is disabled. All of that must be done without a button.

JavaScript

Advertisement

Answer

In your example you’ve forget to call the method JavaJTextFieldActionListner. I’ve remove it and move the code into constructor. Also I’ve added handling of a wrong input. Here is the result:

JavaScript
Advertisement