Connecter dynamiquement les beans
public class Introspection2 extends java.awt.Frame{
Class laClasseBouton,laClasseCompteur,laClasseAfficheur;
Method setLabelMethod, setTextMethod,
addActionListenerMethod, addPropertyChangeListenerMethod;
static Introspection2 demo;
public static void main(String args[])throws Exception { demo= new Introspection2(); demo.init(); }
public void init()throws Exception {
laClasseBouton=Class.forName(" java.awt.Button ");
laClasseCompteur=Class.forName("compteur.Compteur");
laClasseAfficheur=Class.forName("affichage.Afficheur");
bout=(java.awt.Button )laClasseBouton.newInstance();
compt=(compteur.Compteur)laClasseCompteur.newInstance();
aff=(affichage.Afficheur)laClasseAfficheur.newInstance();
setLabelMethod=laClasseBouton.getMethod("setLabel", new Class[]{String.class});
setLabelMethod.invoke(bout,new String[]{"10"});
setTextMethod=laClasseAfficheur.getMethod("setText", new Class[]{String.class});
setTextMethod.invoke(aff,new String[]{"0"});
addActionListenerMethod=laClasseBouton.getMethod("addActionListener", new Class[]{java.awt.event.ActionListener.class});
addActionListenerMethod.invoke(bout,new java.awt.event.ActionListener[]{compt});
addPropertyChangeListenerMethod= laClasseCompteur.getMethod("addPropertyChangeListener",
new Class[]{java.beans.PropertyChangeListener.class});
addPropertyChangeListenerMethod.invoke(compt,newjava.beans.PropertyChangeListener[]{aff});
add(bout,"West"); add(aff,"East"); pack(); setVisible(true);