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 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
| import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
public class LivretsDE extends JFrame{
// panel principal
private JPanel panel = new JPanel();
// panel premire ligne
private JPanel panel1 = new JPanel();
// panel centre
private JPanel panel2 = new JPanel();
private JLabel jl0 = new JLabel("Livret entrainer");
private JTextField jtf1 = new JTextField();
private JButton bouton1 = new JButton("Dfinir");
// livret choisi par utilisateur
private JLabel jl1 = new JLabel();
private JLabel jl2 = new JLabel("*");
private JLabel jl3 = new JLabel("=");
// deuxime chiffre du calcul
private JLabel [] tableau2 = new JLabel[20];
// rponses entres par utilisateur
private JTextField [] tableau1 = new JTextField[20];
public LivretsDE(){
this.setTitle("Livrets");
this.setSize(480, 700);
this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
this.setLocationRelativeTo(null);
jtf1.setPreferredSize(new Dimension(70, 30));
jtf1.setForeground(Color.GREEN);
panel.setBackground(Color.WHITE);
panel.setLayout(new BorderLayout());
panel.add(panel1, BorderLayout.NORTH);
panel1.add(jl0);
panel1.add(jtf1);
panel1.add(bouton1);
panel.add(panel2, BorderLayout.CENTER);
for (int compteur = 0; compteur < 20; compteur++){
panel2.add(tableau2[compteur]);
}
// Pression sur le bouton => effectuer la class Bouton1Listener
bouton1.addActionListener(new Bouton1Listener());
this.setContentPane(panel);
this.setVisible(true);
}
class Bouton1Listener implements ActionListener{
public void actionPerformed(ActionEvent arg0) {
String text = jtf1.getText();
jl1.setText(text);
jl2.setText(text);
}
}
public static void main(String[] args) {
LivretsDE LD = new LivretsDE();
}
} |