Only allowing numbers and a symbol (-) to be typed into a JTextField
问题 I\'m trying to create a math quiz and I only want the user to be able to enter numbers whether they\'re negative or positive. Is there any way to do so? I\'ve thought of using Regular Expressions but I\'ve heard that they are bad to use. I tried using a keylistener but then what if the user pastes? I\'ve tried parsing the string to get an integer but then the negative symbol will not work. Any ideas? package com.quiz.ui; import java.awt.BorderLayout; import java.awt.event.KeyEvent; import