Answer the question
In order to leave comments, you need to log in
Calculator in Java, how to make a backspace button?
How to make a BackSpace button in a graphing calculator?
private void buttonBackspaceActionPerformed(java.awt.event.ActionEvent evt) {
String t = textField.getText();
if (t.isEmpty()){
textField.setText("0");
} else {
textField.setText(t.substring(0, t.length() - 1));
}
}
Answer the question
In order to leave comments, you need to log in
if (t.isEmpty() || t.getText().equals("0")){
PS Do you want a cross-platform calculator? If not, then why in Java?
But this code of mine, when you delete all the numbers, first gives out 0, when you press it again, it gives an empty string, and so on.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question