-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathButton.java
More file actions
201 lines (179 loc) · 4.19 KB
/
Button.java
File metadata and controls
201 lines (179 loc) · 4.19 KB
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.ImageIcon;
import javax.swing.JButton;
/**
* Controls the functionality of all buttons.
*
* @author Michael Nipper
*
*/
public class Button extends JButton implements ActionListener {
private JButton button;
private int xPosition, yPosition, width, height = 0;
private ImageIcon upImage, downImage;
protected MediaController mediaController;
/**
* Default constructor.
*/
public Button() {
button = new JButton();
}
/**
* METHOD OVERLOAD
*
* @param x
* int The x position of the button.
* @param y
* int The y position of the button.
* @param upImage
* ImageIcon The image to use when the button is not being
* pressed.
* @param downImage
* ImageIcon The image to use when the button is being pressed.
*/
public Button(int x, int y, ImageIcon upImage, ImageIcon downImage) {
button = new JButton();
setGraphicUp(upImage);
setGraphicDown(downImage);
xPosition = x;
yPosition = y;
}
/**
* Set the image to use for a button when it is not being pressed.
*
* @param image
* imageIcon The image to use.
*/
public void setGraphicUp(ImageIcon image) {
upImage = image;
}
/**
* Set the image to use for a button when it is being pressed.
*
* @param image
* imageIcon The image to use.
*/
public void setGraphicDown(ImageIcon image) {
downImage = image;
}
/**
* Get the image to use when a button is not being pressed.
*
* @return ImageIcon The image for a non-pressed button.
*/
public ImageIcon getGraphicUp() {
return upImage;
}
/**
* Get the image to use when a button is being pressed.
*
* @return ImageIcon The image for a pressed button.
*/
public ImageIcon getGraphicDown() {
return downImage;
}
/**
* Set the position of a button.
*
* @param x
* int The x coordinate.
* @param y
* int The y coordinate.
*/
public void setPosition(int x, int y) {
button.setLocation(x, y);
}
/**
* Warn the developer if a button does not have an associated action set.
*
* @Override
*/
public void actionPerformed(ActionEvent e) {
System.out.println("No action has been set for this button!");
}
/**
* Gets the x coordinate of the button.
*
* @return int The x coordinate of a button.
*/
public int getxPosition() {
return xPosition;
}
/**
* Sets the x coordinate of a button.
*
* @param xPosition
* int Sets the x coordinate of a button.
*/
public void setxPosition(int xPosition) {
this.xPosition = xPosition;
}
/**
* Gets the y coordinate of the button.
*
* @return int The y coordinate of a button.
*/
public int getyPosition() {
return yPosition;
}
/**
* Sets the y coordinate of a button.
*
* @param xPosition
* int Sets the y coordinate of a button.
*/
public void setyPosition(int yPosition) {
this.yPosition = yPosition;
}
/**
* Get the width of the button.
*
* @return int Gets the width of the button.
*/
public int getWidth() {
return width;
}
/**
* Sets the width of the button.
*
* @param width
* The desired width.
*/
public void setWidth(int width) {
this.width = width;
}
/**
* Get the height of the button.
*/
public int getHeight() {
return height;
}
/**
* Set the height of the button.
*
* @param height
* int The desired height of the button.
*/
public void setHeight(int height) {
this.height = height;
}
/**
* Set a media controller object for the button to use.
*
* @param m
* MediaController A MediaController object for the buttons to
* control.
*/
public void setMediaController(MediaController m) {
mediaController = m;
}
/**
* Get the MediaController object which controls this button.
*
* @return A MediaController object.
*/
public MediaController getMediaController() {
return mediaController;
}
}