Container

Container - Java - Programmation

Marsh Posté le 05-07-2005 à 17:42:38    

Bonjour,
j'ai fais une méthode pour me renvoyer tous les composants d'un panel mais il fai le test uniquement sur le dernier if :else if (comp instanceof java.awt.Container)et ne fait pas de test sur les premiers.
pouvez vous m'aider?
voici une partie du code.
merci
 
public void parcourir_container(Container cont){
        Component comp=this;
        for(int i=0;i<=cont.getComponentCount();i++){
           if(comp instanceof javax.swing.JTextField){
                System.out.println(cont.getComponent(i));
            }else if(comp instanceof javax.swing.JComboBox){
                System.out.println(cont.getComponent(i));
            }else if(comp instanceof javax.swing.JRadioButton){
                System.out.println(cont.getComponent(i));
            }else if (comp instanceof java.awt.Container){
                parcourir_container(cont);
                System.out.println(cont.getComponent(i));                
            }
         }          
    }

Reply

Marsh Posté le 05-07-2005 à 17:42:38   

Reply

Marsh Posté le 05-07-2005 à 22:38:59    

Comment tu le sais ?

Reply

Marsh Posté le 05-07-2005 à 22:44:33    

vive le polymorphisme ...

Reply

Sujets relatifs:

Leave a Replay

Make sure you enter the(*)required information where indicate.HTML code is not allowed