-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathProgressBar.java
More file actions
93 lines (82 loc) · 2.14 KB
/
ProgressBar.java
File metadata and controls
93 lines (82 loc) · 2.14 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.JLabel;
import javax.swing.Timer;
/**
* The progress bar, which controls the movement of a ProgressButton object.
*
* @author Michael Nipper
*
*/
public class ProgressBar implements ActionListener {
private JLabel progressLabel;
private int duration = 0;
private int position = 0;
private ProgressButton progressButton;
private MediaController mediaController;
private Timer timer;
private Window window;
/**
*
* @param pl
* The JLabel for the duration label.
* @param pg
* The ProgressButton to attach to the ProgressBar.
* @param w
* The Window object to attach the ProgressBar.
*/
public ProgressBar(JLabel pl, ProgressButton pg, Window w) {
progressLabel = pl;
progressButton = pg;
timer = new Timer(1000, this);
window = w;
}
/**
* Start the graphics for the ProgressBar.
*/
public void start() {
if (mediaController.isPlaylistSet()) {
timer.start();
duration = mediaController.getCurrentSong().getSongLengthSeconds();
}
}
/**
* Stop the graphics for the ProgressBar.
*/
public void stop() {
timer.stop();
}
/**
* Refresh the ProgressBar graphics and labels.
*
* @param mc
* The MediaController that is controlling the ProgressBar.
*/
public void refresh(MediaController mc) {
stop();
position = 0;
mediaController = mc;
progressLabel.setText("0:00");
progressButton.setLocation(30, 51);
progressButton.setxPosition(30);
progressButton.setyPosition(51);
progressButton.refreshPixelRounder();
}
@Override
public void actionPerformed(ActionEvent arg0) {
if (position < duration) {
position++;
String secondLabel = "" + position % 60;
if (position % 60 < 10) {
secondLabel = "0" + position % 60;
}
progressLabel.setText(position / 60 + ":" + secondLabel);
progressButton.moveButton(((1.0 / duration) * 215));
} else {
mediaController.nextTrack();
refresh(mediaController);
window.refreshLabels();
start();
}
}
}