Only chiffre dans un texfield en java

Fermé
rinking - 2 avril 2005 à 03:36
choubaka Messages postés 39375 Date d'inscription jeudi 4 avril 2002 Statut Modérateur Dernière intervention 14 avril 2024 - 2 avril 2005 à 08:11
Bonjour,
Je voudrais savoir comment faire pour autoriser seulement la saisie de chiffre dans un TextField (ou JTextField) en java.

Pourriez vous me donner un exemple de code.

SVP Merci.

Rinking
A voir également:

1 réponse

choubaka Messages postés 39375 Date d'inscription jeudi 4 avril 2002 Statut Modérateur Dernière intervention 14 avril 2024 2 100
2 avril 2005 à 08:11
salut

tu dois tester le String avec

public static Integer valueOf(String s)
                       throws NumberFormatExceptionReturns an Integer object holding the value of the specified String. The argument is interpreted as representing a signed decimal integer, exactly as if the argument were given to the parseInt(java.lang.String) method. The result is an Integer object that represents the integer value specified by the string. 
In other words, this method returns an Integer object equal to the value of: 

new Integer(Integer.parseInt(s)) 

Parameters:
s - the string to be parsed. 
Returns:
an Integer object holding the value represented by the string argument. 
Throws: 
NumberFormatException - if the string cannot be parsed as an integer.


dans la gestion de l'erreur, il suffit de signaler à l'utilisateur qu'il doit recommencer correctement l'opération
0