-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMusicEnabledCheckbox.java
More file actions
40 lines (32 loc) · 937 Bytes
/
MusicEnabledCheckbox.java
File metadata and controls
40 lines (32 loc) · 937 Bytes
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
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JCheckBox;
import javax.swing.SwingConstants;
@SuppressWarnings("serial")
public class MusicEnabledCheckbox extends JCheckBox {
private static boolean musicEnabled = true;
public MusicEnabledCheckbox(){
super ("Music Enabled", musicEnabled);
super.setHorizontalTextPosition(SwingConstants.LEFT);
super.addActionListener(new MusicCheckboxListener(this));
}
public static boolean musicEnabled(){
return musicEnabled;
}
class MusicCheckboxListener implements ActionListener {
private MusicEnabledCheckbox checkbox;
public MusicCheckboxListener(MusicEnabledCheckbox checkbox){
this.checkbox = checkbox;
}
public void actionPerformed(ActionEvent arg0) {
if (!checkbox.isSelected()){
Songs.song1.stop();
musicEnabled = false;
}
else{
Songs.song1.loop();
musicEnabled = true;
}
}
}
}