Java JButton Mouse setMouseListener(final JButton button, String iconPath)

Here you can find the source of setMouseListener(final JButton button, String iconPath)

Description

set Mouse Listener

License

Apache License

Declaration

public static void setMouseListener(final JButton button, String iconPath) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.ImageIcon;
import javax.swing.JButton;

public class Main {
    public static void setMouseListener(final JButton button, String iconPath) {

        final ImageIcon imagePressed = new ImageIcon(iconPath + "_p.png");
        final ImageIcon image = new ImageIcon(iconPath + ".png");

        button.addMouseListener(new MouseAdapter() {
            public void mousePressed(MouseEvent e) {
                button.setIcon(imagePressed);
            }/*from   w  w  w  . j a v a  2s.  c  o  m*/

            public void mouseReleased(MouseEvent e) {
                button.setIcon(image);
            }
        });
    }
}