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 82 83 84 85 86 87
| import java.awt.event.*;
import javax.swing.*;
@SuppressWarnings("serial")
public class Fenetre extends JFrame implements ActionListener {
private JButton Btn1, Btn2, Btn3;
private JTextField JTF1;
private JLabel JLTexte1, JL1, JL2;
private JTextArea JTA1;
public Fenetre(){
super("Titre : ");
setSize(275, 500);
setLocation(500, 0);
setVisible(true);
setAlwaysOnTop(false);
setResizable(false);
setLayout(null);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
///////////////////////////////////////////////
//Les labels
JL1 = new JLabel("Chien");
JL1.setBounds(31, 80, 85, 25);
add(JL1);
JL2 = new JLabel("Chat");
JL2.setBounds(171, 80, 85, 25);
add(JL2);
//le JTextField
JTF1 = new JTextField("Tapez votre texte ici");
JTF1.setBounds(70, 10, 140, 25);
add(JTF1);
//Les boutons
Btn1 = new JButton("Label N¤ 1");
Btn1.setBounds(10, 50, 100, 25);
Btn1.addActionListener(this);
add(Btn1);
Btn2 = new JButton("Label N¤ 2");
Btn2.setBounds(140, 50, 120, 25);
Btn2.addActionListener(this);
add(Btn2);
Btn3 = new JButton("TextArea");
Btn3.setBounds(10, 120, 250, 25);
Btn3.addActionListener(this);
add(Btn3);
//Le JTextArea + Scrollbar
JTA1 = new JTextArea();
JScrollPane scrollbar = new JScrollPane(JTA1);
scrollbar.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
scrollbar.setBounds(10, 170, 250, 250);
add(scrollbar);
}
public static void main(String[] args) {
new Fenetre();
}
@Override
public void actionPerformed(ActionEvent e) {
if(e.getSource() == Btn1){
JL1.setText(JTF1.getText());
}
if(e.getSource() == Btn2){
JL2.setText(JTF1.getText());
}
if(e.getSource() == Btn3){
JTA1.append(JL1.getText() + " et " + JL2.getText());
JTA1.append("\n");
}
}
} |