Récupérer une donnée d'un vector.

Résolu/Fermé
snp3109 Messages postés 77 Date d'inscription mardi 27 juillet 2010 Statut Membre Dernière intervention 10 juillet 2014 - 16 mai 2013 à 09:46
snp3109 Messages postés 77 Date d'inscription mardi 27 juillet 2010 Statut Membre Dernière intervention 10 juillet 2014 - 16 mai 2013 à 21:42
Bonjour à tous,
Je vous présente mon problème. Je créé un vector avec à l'intérieur plusieurs données. Quand je l'affiche dans la console ça m'affiche ceci :

javax.swing.JLabel[,50,450,42x25,alignmentX=0.0,alignmentY=0.0,border=,flags=25165832,maximumSize=,minimumSize=,preferredSize=,defaultIcon=,disabledIcon=,horizontalAlignment=LEADING,horizontalTextPosition=TRAILING,iconTextGap=4,labelFor=,text= Voie 1,verticalAlignment=CENTER,verticalTextPosition=CENTER]

Je souhaiterai récupérer le 5ème élément (flags=25165832) de ce vector et l'intégrer dans un int. On m'a parlé de "substring" mais je n'arrive pas à l'utiliser.
Merci à tous de votre patience.
Snp3109

1 réponse

KX Messages postés 16734 Date d'inscription samedi 31 mai 2008 Statut Modérateur Dernière intervention 24 avril 2024 3 015
16 mai 2013 à 19:10
Tu peux faire comme ça :

public static int getFlags(JComponent comp)
{
    return Integer.parseInt(comp.toString().split("=|,")[12]);
}

public static void main(String[] args)
{
    JLabel label = new JLabel();      
    System.out.println(getFlags(label));
}
1
snp3109 Messages postés 77 Date d'inscription mardi 27 juillet 2010 Statut Membre Dernière intervention 10 juillet 2014 3
16 mai 2013 à 21:42
Merci beaucoup j'ai obtenu ce que je voulais.
Bonne soirée.
0