如何使“sueldo、salud、AFP”文本字段只接受数字?
private void sueldoActionPerformed(java.awt.event.ActionEvent evt) {
}
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
String sueldo = this.sueldo.getText();
int sueldoInt = Integer.parseInt(sueldo);
String salud = this.salud.getText();
int saludInt = Integer.parseInt(salud);
String afp = this.afp.getText();
int afpInt = Integer.parseInt(afp);
String otros = this.otros.getText();
int otrosInt = Integer.parseInt(otros);
double saludD = sueldoInt * (saludInt * 0.01);
double afpD = sueldoInt * (afpInt * 0.01);
int calcular = (int) (sueldoInt - saludD - afpD - otrosInt);
JOptionPane.showMessageDialog(null,+calcular);
最佳答案
您可以将 JFormattedTextField
与 MaskFormatter
结合使用:
MaskFormatter formatter= new MaskFormatter("########");
JFormattedTextField textField = new JFormattedTextField(formatter);
关于java - 限制 jtextfield 仅接受数字?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33679959/