This repository has been archived by the owner on Mar 20, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathKButton.java
98 lines (88 loc) · 1.93 KB
/
KButton.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
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
94
95
96
97
98
/**
* Created by Dastan21
*/
import java.net.URL;
import javax.swing.JButton;
import javax.swing.ImageIcon;
import javax.swing.event.*;
import java.awt.*;
public class KButton extends JButton {
private Color color;
private String path;
private String type;
private boolean isEnabled;
/**
* Default constructor
*/
public KButton() {
// Color
setContentAreaFilled(false);
setOpaque(true);
update();
setFocusPainted(false);
addChangeListener(new ChangeListener() {
@Override
public void stateChanged(ChangeEvent event) {
if (path != null){
if (getModel().isRollover()){
// if (isEnabled)
if (isEnabled())
setIcon(new ImageIcon(getClass().getResource(path+type+"_selected.png")));
} else {
setIcon(new ImageIcon(getClass().getResource(path+type+".png")));
}
}
if (getModel().isPressed()) setBackground(color);
}
});
}
/**
* Update the button's background color
*/
private void update(){
setBackground(color);
}
/**
* Set the color of the button
* @param color from Color class
*/
public void setColor(Color color){
this.color = color;
update();
}
/**
* Set the image's path of the button
* @param path string of path
*/
public void setPath(String path){
this.path = path;
}
/**
* Get the image's path of the button
* @return String path
*/
public String getPath(){
return this.path;
}
/**
* Set the image's type of the button
* @param type string of type
*/
public void setType(String type){
this.type = type;
}
/**
* Get the image's type of the button
* @return String type
*/
public String getType(){
return this.type;
}
/**
* Set the button's state
* @param state boolean of isEnabled
*/
public void setState(boolean state){
this.isEnabled = state;
}
}