-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPlayButton.java
More file actions
93 lines (81 loc) · 2.34 KB
/
PlayButton.java
File metadata and controls
93 lines (81 loc) · 2.34 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
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.ImageIcon;
/**
* The play/pause button for the GUI.
*
* @author Michael Nipper
*
*/
public class PlayButton extends Button implements ActionListener {
private boolean isPlayButton = true;
private ProgressBar progressBar;
/**
* @param x
* x-coordinate for the button
* @param y
* y-coordinate for the button
* @param width
* width of the button
* @param height
* height of the button
* @param upImage
* image to show when the button is not being pressed
* @param downImage
* image to show when the button is being pressed
*/
public PlayButton(int x, int y, int width, int height, ImageIcon upImage,
ImageIcon downImage) {
super(x, y, upImage, downImage);
addActionListener(this);
this.setWidth(width);
this.setHeight(height);
}
@Override
public void actionPerformed(ActionEvent e) {
if (getMediaController().isPlaylistSet()) {
if (isPlayButton) {
getMediaController().play();
progressBar.start();
makePauseButton();
} else {
getMediaController().pause();
progressBar.stop();
makePlayButton();
}
}
}
/**
* Adjust the graphics of the play button to make it a pause button.
*/
public void makePlayButton() {
isPlayButton = true;
ImageIcon pause = new ImageIcon("images/playButton.png");
ImageIcon pausePressed = new ImageIcon("images/playButtonPressed.png");
this.setGraphicUp(pause);
this.setGraphicDown(pausePressed);
this.setIcon(this.getGraphicUp());
this.setPressedIcon(this.getGraphicDown());
}
/**
* Adjust the graphics of the pause button to make it a play button.
*/
public void makePauseButton() {
isPlayButton = false;
ImageIcon pause = new ImageIcon("images/pauseButton.png");
ImageIcon pausePressed = new ImageIcon("images/pauseButtonPressed.png");
this.setGraphicUp(pause);
this.setGraphicDown(pausePressed);
this.setIcon(this.getGraphicUp());
this.setPressedIcon(this.getGraphicDown());
}
/**
* Set a ProgressBar object for the PlayButton to control.
*
* @param p
* The ProgressBar object to control.
*/
public void setProgressBar(ProgressBar p) {
progressBar = p;
}
}