Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
import javax.swing.*;
import java.awt.event.*;
public class NumericInputField extends JTextField {
public NumericInputField() {
this.addKeyListener(new KeyAdapter() {
public void keyTyped(KeyEvent e) {
char c = e.getKeyChar();
if (!((Character.isDigit(c)) ||
(c == KeyEvent.VK_BACK_SPACE) ||
(c == KeyEvent.VK_DELETE))) {
getToolkit().beep();
e.consume();
}
}
});
}
public static void main(String args[]) {
JFrame f = new JFrame("NumericExample");
JTextField numField = new NumericInputField();
f.getContentPane().add(numField);
f.setSize(200,300);
f.setVisible(true);
}
}