| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 
 |  
/*Classe ConstructeurIHM*/
import java.awt.BorderLayout;
import java.awt.Dimension;
 
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JTextField;
 
public class ConstructeurIHM {
 
    public JButton bouton;
    public JTextField champ;
 
    public ConstructeurIHM(GestionIHM gestionnaire){
 
        JFrame aFrame=new JFrame();
 
        bouton = new JButton("bouton");
        bouton.setPreferredSize(new Dimension(50,20));
        bouton.addActionListener(gestionnaire);
 
 
        champ = new JTextField();
        champ.setPreferredSize(new Dimension(150,30));
        champ.addActionListener(gestionnaire);
 
        aFrame.getContentPane().setLayout(new BorderLayout());
 
        aFrame.getContentPane().add(bouton,BorderLayout.NORTH);
 
        aFrame.getContentPane().add(champ, BorderLayout.SOUTH);
 
        aFrame.pack();
 
        aFrame.setVisible(true);
}
}
/*Classe GestionIHM*/
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
 
public class GestionIHM implements ActionListener{
 
    ConstructeurIHM ihm;
    public GestionIHM(){
            ihm = new ConstructeurIHM(this);
    }
 
    public static void main(String[] args)
    {
           GestionIHM gestionnaire = new GestionIHM();
    }
 
    public void actionPerformed(ActionEvent evt){
             if(evt.getActionCommand().equals("bouton")){
                     ihm.champ.setText("salut");
             }
    }
} | 
Partager