Skip to content

Commit

Permalink
Setting root jpanel visibility to false as a crash prevention strateg…
Browse files Browse the repository at this point in the history
…y. Playing sounds on mute and unmute.
  • Loading branch information
tarehart committed Nov 6, 2013
1 parent 119b616 commit 2ec5f4c
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 7 deletions.
6 changes: 3 additions & 3 deletions src/tarehart/alter/AlterForm.form
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@
</grid>
</constraints>
<properties>
<background color="-13421773"/>
<background awt-color="darkGray"/>
</properties>
<border type="none"/>
<children/>
Expand Down Expand Up @@ -199,7 +199,7 @@
</grid>
</constraints>
<properties>
<background color="-13421773"/>
<background awt-color="darkGray"/>
</properties>
<border type="none"/>
<children/>
Expand Down Expand Up @@ -236,7 +236,7 @@
</grid>
</constraints>
<properties>
<background color="-13421773"/>
<background awt-color="darkGray"/>
</properties>
<border type="none"/>
<children/>
Expand Down
11 changes: 9 additions & 2 deletions src/tarehart/alter/AlterForm.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ public void propertyChange(PropertyChangeEvent evt) {
if ("progress".equals(evt.getPropertyName())) {
noiseLevel = (Integer) evt.getNewValue();

if (noiseLevel < progressBar1.getMinimum()) noiseLevel = progressBar1.getMinimum();
if (noiseLevel > progressBar1.getMaximum()) noiseLevel = progressBar1.getMaximum();

progressBar1.setValue(noiseLevel);

if (noiseLevel >= slider1.getValue()) {
Expand Down Expand Up @@ -286,10 +289,14 @@ public void windowIconified(WindowEvent e) { }
public void windowDeiconified(WindowEvent e) { }

@Override
public void windowActivated(WindowEvent e) { }
public void windowActivated(WindowEvent e) {
rootPanel.setVisible(true);
}

@Override
public void windowDeactivated(WindowEvent e) { }
public void windowDeactivated(WindowEvent e) {
rootPanel.setVisible(false);
}
};
}

Expand Down
35 changes: 35 additions & 0 deletions src/tarehart/alter/SoundPlayer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package tarehart.alter;

import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.Clip;
import java.net.URL;

public class SoundPlayer {

private static synchronized void playSound(final String name) {
new Runnable() {
public void run() {
try {
Clip clip = AudioSystem.getClip();

URL url = SoundPlayer.class.getResource("resources/" + name);
AudioInputStream inputStream = AudioSystem.getAudioInputStream(url);
clip.open(inputStream);
clip.start();
} catch (Exception e) {
e.printStackTrace();
}
}
}.run();
}

public static void beepBeep() {
playSound("beepbeep.wav");
}

public static void boop() {
playSound("boop.wav");
}

}
15 changes: 13 additions & 2 deletions src/tarehart/alter/TalkingJudge.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ public void actionPerformed(ActionEvent e) {
@Override
public void actionPerformed(ActionEvent e) {
mutedForSneeze = false;
if (!isManuallyMuted()) {
SoundPlayer.boop();
}
}
});
sneezeTimer.setRepeats(false);
Expand Down Expand Up @@ -77,7 +80,7 @@ public void sneezeIncoming() {
if (sneezeTimer.isRunning()) {
sneezeTimer.restart();
} else {
presser.release();
engageMute();
mutedForSneeze = true;
sneezeTimer.start();
}
Expand All @@ -87,13 +90,21 @@ public void toggleManualMute() {
if (!mutedManually) {
mutedManually = true;
mutedForSneeze = false;
presser.release();
engageMute();
sneezeTimer.stop();
} else {
mutedManually = false;
if (!isMutedForSneeze()) {
SoundPlayer.boop();
}
}
}

private void engageMute() {
presser.release();
SoundPlayer.beepBeep();
}

public boolean isManuallyMuted() {
return mutedManually;
}
Expand Down
Binary file added src/tarehart/alter/resources/beepbeep.wav
Binary file not shown.
Binary file added src/tarehart/alter/resources/boop.wav
Binary file not shown.

0 comments on commit 2ec5f4c

Please sign in to comment.