Bonjour,
Je suis débutant et je n'arrive pas à me servir des actionlistener.
Pour le moment je voudrais que le message "click" s'affiche lorsque je clique sur le bouton "triangle".

J'ai le message d'erreur suivant :
Exception in thread "main" java.lang.ClassCastException: javax.swing.JButton cannot be cast to java.awt.event.ActionListener
at tp.dessinons.FenPrincipal.<init>(FenPrincipal.java:37)
at tp.dessinons.FenPrincipal.main(FenPrincipal.java:27)

Voila le code :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
package tp.dessinons;
 
import java.awt.BorderLayout;
import java.awt.Color;
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;
 
 
/**
 *
 * @author pinps
 */
public class FenPrincipal extends JFrame {
 
    /**
     * @param args the command line arguments
public     */
    public static void main(String[] args) {
        FenPrincipal fen=new FenPrincipal();
        fen.setTitle("Dessinons");
        fen.setSize(500,300);
        fen.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        fen.setVisible(true);
 
    }
    public FenPrincipal(){
        JPanel zone_haut=new JPanel();
        JButton btn_triangle=new JButton("Triangle");
        btn_triangle.addActionListener((ActionListener) btn_triangle);
        JButton btn_carre=new JButton("Carré");
        JButton btn_cercle=new JButton("Cercle");
        JButton btn_raz=new JButton("RAZ");
        JLabel lbl_forme=new JLabel("Forme : X");
        JLabel lbl_couleur=new JLabel("Coul. : X");
        zone_haut.add(btn_triangle);
        zone_haut.add(btn_carre);
        zone_haut.add(btn_cercle);
        zone_haut.add(btn_raz);
        zone_haut.add(lbl_forme);
        zone_haut.add(lbl_couleur);
        getContentPane().add(BorderLayout.NORTH, zone_haut);
 
        JPanel zone_bas=new JPanel();
        JButton btn_bleu=new JButton("Bleu");
        btn_bleu.setBackground(Color.blue);
        JButton btn_jaune=new JButton("Jaune");
        btn_jaune.setBackground(Color.yellow);
        JButton btn_rouge=new JButton("Rouge");
        btn_rouge.setBackground(Color.red);
        JButton btn_vert=new JButton("Vert");
        btn_vert.setBackground(Color.green);
        JButton btn_noir=new JButton("Noir");
        btn_noir.setBackground(Color.black);
        zone_bas.add(btn_bleu);
        zone_bas.add(btn_jaune);
        zone_bas.add(btn_rouge);
        zone_bas.add(btn_vert);
        zone_bas.add(btn_noir);
        getContentPane().add(BorderLayout.SOUTH, zone_bas);
 
        JPanel zone_centre=new JPanel();
        zone_centre.setBackground(Color.white);
        getContentPane().add(BorderLayout.CENTER, zone_centre);
    }
 
    public class BoutonForme extends JButton implements ActionListener{
 
        @Override
        public void actionPerformed(ActionEvent e) {
            //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
            System.out.println("click");
        }
 
    }
}
Merci d'avance