private void realizarVenta() { boolean cantidadCorrecta = false; String str = "", strError = "Debes introducir una cantidad válida. Recuerda : \n 1) Sólo debes introducir números enteros; positivos \n 2) Debes dejar a lo más cero artículos en 'stock'"; String strExistencia = tfExistencia.getText(), clave = ""; int cantidad = 0; int existencia = Integer.parseInt(strExistencia); while (cantidadCorrecta == false) { str = JOptionPane.showInputDialog(null, "Cantidad a Vender = "); try { cantidad = Integer.parseInt(str); if ((cantidad < 0) || (cantidad > existencia)) JOptionPane.showMessageDialog(null, strError); else { cantidadCorrecta = true; clave = tfClave.getText(); resultado = lista.venderArticulos(cantidad, existencia); habilitarCampos(true); habilitarBotones(true); print(resultado); } } catch (NumberFormatException nfe) { System.out.println("Error: " + nfe); JOptionPane.showMessageDialog(null, strError); } } }