Here you can find the source of setMouseListener(final JButton button, String iconPath)
public static void setMouseListener(final JButton button, String iconPath)
//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); } }); } }