| 12
 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
 88
 89
 90
 91
 92
 93
 
 |  
public class BoutonImg extends JButton implements MouseListener
{
	private String name;
    private Image img;
 
    public BoutonImg( String  strImg )
    {
            super(strImg);
 
            this.name = strImg;
 
            try {
                img = ImageIO.read(new File("RED.jpg")); 
 
 
                } 
            catch (IOException e)     // Icon icon
               {
                   e.printStackTrace();
               }
 
       this.addMouseListener(this);
    }
 
    public void paintComponent(Graphics g)
    {
 
            Graphics2D g2d = (Graphics2D)g;
            g2d.drawImage(img, 0, 0, this.getWidth(), this.getHeight(), this);
            g2d.setColor(Color.WHITE);
            g2d.drawString(this.name, this.getWidth() / 2 - (this.getWidth() / 2/4), (this.getHeight() / 2) + 5);
 
    }
 
 
    public void mouseClicked(MouseEvent event)   //Pas utile d'utiliser cette méthode ici   
    {                                
    }
 
    public void mouseEntered(MouseEvent event)   // Nous changeons la couleur du boutton en "JAUNE" on met la souris dessus 
 
    {
            try 
            {
               img = ImageIO.read(new File("YELLOW.jpg"));
            } 
            catch (IOException e)
            {                  
                e.printStackTrace();
            }
 
    }
 
    public void mouseExited(MouseEvent event)   //Nous changeons la couleur du boutton en "ORANGE" quand on quitte le bouton
    {                                                              
            try 
            {
               img = ImageIO.read(new File("ORANGE.jpg"));
            }
            catch (IOException e) 
            {                  
                e.printStackTrace();
            }            
    }
 
    public void mousePressed(MouseEvent event) //Nous changeons la couleur du boutton en "BLEU" quand on clic du botton gauche de la sours
    {                                           
            try 
            {
               img = ImageIO.read(new File("BLUE.jpg"));
            } 
            catch (IOException e) 
            {                  
               e.printStackTrace();
            }
 
    }
 
    public void mouseReleased(MouseEvent event) // Nous changeons le fond en orangé pour notre image 
    {                                           // lorsqu'on relâche le clic 
                                                // avec le fichier fondBoutonHover.png                        
            try 
            {
               img = ImageIO.read(new File("ORANGE.jpg"));
            } 
            catch (IOException e) 
            {                    
                e.printStackTrace();
            }               
    }       
 
} | 
Partager