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
| import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JFrame;
public class k extends JFrame {
private Panel zoneDessin = new Panel ();
private Panel zoneChoix = new Panel ();
private Color couleur = Color.BLACK;
Button rouge = new Button ("Rouge");
Button bleu = new Button ("Bleu");
Button ligne = new Button("ligne");
public k(){
add("North",zoneChoix);
zoneChoix.add(ligne);
zoneChoix.add(rouge);
zoneChoix.add(bleu);
add("Center",zoneDessin);
ActionListener Ecouter = new ActionListener() {
public void actionPerformed (ActionEvent e) {
if ((e.getSource() == rouge)&& (e.getSource()== ligne)) {
couleur=Color.RED;
// dessiner une ligne
}
else if ((e.getSource() == bleu) && (e.getSource()== ligne)){
couleur=Color.blue;
// dessiner une ligne
}
}
};
rouge.addActionListener(Ecouter);
}
public static void main(String[] args) {
new k().setVisible(true);
}
} |
Partager