-
Notifications
You must be signed in to change notification settings - Fork 0
/
ActionButton.java
35 lines (32 loc) · 1.11 KB
/
ActionButton.java
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
//ActionButton extends JLabel and takes button text as a parameter to create a button
//Once the ActionButton has been created, addIcon() can be called and passed an image path
//To add an image to the ActionButton
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.border.LineBorder;
public class ActionButton extends JLabel
{
private int defaultBorderSize = 1;
private int buttonSize = 32;
public ActionButton(String btnText){
super(btnText, SwingConstants.CENTER);
setBorder( new LineBorder(Color.pink, defaultBorderSize) );
setForeground( Color.white );
setOpaque(true);
setBackground(Color.black);
addMouseListener(new MouseAdapter() {
public void mouseEntered(MouseEvent evt) {
setBorder( new LineBorder(Color.white, 1) );
setBackground( Color.darkGray );
}
public void mouseExited(MouseEvent evt) {
setBorder( new LineBorder(Color.pink, defaultBorderSize) );
setBackground(Color.black);
}
});
}
public void addIcon(String path){
setIcon(Resource_Manager.loadResourceScaled(path, buttonSize, buttonSize));
}
}