Skip to content

Commit cbbaab1

Browse files
author
extremq
committed
Add alarm sfx.
1 parent baf8799 commit cbbaab1

File tree

6 files changed

+34
-1
lines changed

6 files changed

+34
-1
lines changed

.idea/artifacts/Pomodoro_jar.xml

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/misc.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Pomodoro.iml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
<component name="NewModuleRootManager" inherit-compiler-output="true">
44
<exclude-output />
55
<content url="file://$MODULE_DIR$">
6+
<sourceFolder url="file://$MODULE_DIR$/res" type="java-resource" />
67
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
78
</content>
89
<orderEntry type="inheritedJdk" />

res/alarm.wav

361 KB
Binary file not shown.

src/META-INF/MANIFEST.MF

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Manifest-Version: 1.0
2+
Main-Class: com.codebind.App
3+

src/com/codebind/App.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import javax.swing.*;
44
import java.awt.event.ActionEvent;
55
import java.awt.event.ActionListener;
6+
import javax.sound.sampled.*;
7+
import java.net.URL;
68
import java.io.File;
79
import java.io.FileInputStream;
810
import java.io.InputStream;
@@ -120,7 +122,9 @@ private void endFocusPeriod() {
120122
setEnableButtonStop(false);
121123
setTimerStopped(false);
122124
setLabelTimer("00:00");
125+
123126
flashWindow();
127+
playAlarmSound();
124128

125129
JOptionPane.showMessageDialog(null, Locale.FOCUS_DONE_MESSAGE_ALERT);
126130
}
@@ -140,7 +144,9 @@ private void endBreakPeriod() {
140144
setEnableButtonStop(false);
141145
setTimerStopped(false);
142146
setLabelTimer("00:00");
147+
143148
flashWindow();
149+
playAlarmSound();
144150

145151
JOptionPane.showMessageDialog(null, Locale.BREAK_DONE_MESSAGE_ALERT);
146152
}
@@ -152,6 +158,21 @@ private static void flashWindow() {
152158
frame.setAlwaysOnTop(false);
153159
}
154160

161+
private void playAlarmSound() {
162+
URL url = this.getClass().getClassLoader().getResource("alarm.wav");
163+
try {
164+
assert url != null;
165+
AudioInputStream audioIn = AudioSystem.getAudioInputStream(url);
166+
Clip clip = AudioSystem.getClip();
167+
168+
clip.open(audioIn);
169+
clip.start();
170+
}
171+
catch (Exception e) {
172+
System.out.println(e.getMessage());
173+
}
174+
}
175+
155176
public App() {
156177
// Start button logic
157178
buttonStart.addActionListener(new ActionListener() {

0 commit comments

Comments
 (0)