1 2 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 61 62 63 64 65 66
|
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
class Fenetre extends JFrame{
protected JTextField champSaisie, champResultat;
private JButton b_Calcul, b_Quitter;
public Fenetre(){
setTitle("exemple");
Container cf = this.getContentPane();
JPanel p1 = new JPanel();
p1.add(new JLabel("Donnez une suite de mots :"));
champSaisie = new JTextField(20);
p1.add(champSaisie);
cf.add("North",p1);
JPanel p2 = new JPanel();
p2.setLayout(new FlowLayout(FlowLayout.RIGHT));
p2.add(new JLabel("Resultat du calcul :"));
champResultat = new JTextField(20);
p2.add(champResultat);
cf.add("Center",p2);
JPanel p3 = new JPanel();
p3.setLayout(new FlowLayout(FlowLayout.RIGHT));
b_Calcul = new JButton("CALCUL");
b_Quitter = new JButton("QUITTER");
p3.add(b_Calcul);
p3.add(b_Quitter);
cf.add("South",p3);
Delegue1 d1 = new Delegue1(this);
Delegue2 d2 = new Delegue2();
b_Calcul.addActionListener(d1);
b_Quitter.addActionListener(d2);
}
}
class Delegue1 implements ActionListener{
private Fenetre ff;
public Delegue1 (Fenetre f){
ff = f;
}
public void actionPerformed(ActionEvent e){
System.out.println("Fin par bouton QUITTER");
System.exit(0);
}
}
class Delegue2 implements ActionListener{
public void actionPerformed(ActionEvent e){
String res = ff.champSaisie.getText();
ff.champResultat.setText(res.toUpperCase());
}
}
public class swgFenetre{
public static void main(String[] args){
Fenetre f1 = new Fenetre();
f1.pack(); //ou bien f1.setSize(400,140);
f1.setVisible(true);
}
} |
Partager