import java.awt.event.MouseEvent; import java.awt.event.MouseListener; import javax.swing.ImageIcon; import javax.swing.JButton; /** * ToolIcon is an extension of JButton. When the button is clicked then * the toolSelected is switched to its corresponding tool. Each command has * an id. **/ public class ToolIcon extends JButton implements MouseListener { private int commandInt; /** Creates a default ToolIcon. **/ public ToolIcon(){} /** Creates a ToolIcon that takes in a string and a command integer. **/ public ToolIcon(String iconPath, int commandInt) { // createa JButton with an image with the path and sets the command id super(new ImageIcon(iconPath)); this.commandInt = commandInt; addMouseListener(this); } /** * If mouse is clicked then it is selected and the others arent and checks * if there is a special panel for this tool. **/ public void mouseClicked(MouseEvent e) { ToolBox.tools[ToolBox.toolSelected].setEnabled(true); setEnabled(!isEnabled()); ToolBox.toolSelected = commandInt; ControlClass.sBox.choosePanel(); } /** Invoked when the mouse is released. **/ public void mouseReleased(MouseEvent e){} /** Invoked when the mouse is pressed. **/ public void mousePressed(MouseEvent e){} /** Invoked when the mouse enters a component. **/ public void mouseEntered(MouseEvent e){} /** Invoked when the mouse exits a component. **/ public void mouseExited(MouseEvent e){} }