944,155 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 3050
  • Java RSS
Sep 15th, 2004
0

error sound in a calculctor

Expand Post »
i would like to add sound in my java calculator when an error occurs(e.g when operation *and / are pressed).please help me with the sound code.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
kelvin is offline Offline
2 posts
since Aug 2004
Sep 15th, 2004
0

Re: error sound in a calculctor

Hi.
The following link would probably help.
Java: Beep
Reputation Points: 53
Solved Threads: 1
Posting Whiz
red_evolve is offline Offline
313 posts
since Jun 2003
Sep 15th, 2004
0

Re: error sound in a calculctor

You can always play a sound from a file like this:

Java Syntax (Toggle Plain Text)
  1. import java.awt.*;
  2. import javax.swing.*;
  3. import java.applet.*;
  4. import java.awt.event.*;
  5. import java.net.*;
  6.  
  7. public class Sound extends JFrame implements ActionListener {
  8. AudioClip song;
  9. public Sound() {
  10. super("Sounds");
  11. setSize(200,130);
  12. setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  13. Container pane = getContentPane();
  14. FlowLayout flo = new FlowLayout();
  15. pane.setLayout(flo);
  16. JButton btn = new JButton("Press");
  17. pane.add(btn);
  18. btn.addActionListener(this);
  19. setContentPane(pane);
  20. setVisible(true);
  21. }
  22.  
  23. public void actionPerformed(ActionEvent event) {
  24.  
  25.  
  26.  
  27. String source = event.getActionCommand();
  28.  
  29. if (source == "Press") {
  30. try {
  31. URL songURL = new URL("file: errorSound.wav");
  32. song = JApplet.newAudioClip(songURL);
  33. song.play();
  34. } catch (MalformedURLException malform) {
  35. System.out.println(malform.toString());
  36. }
  37. }
  38. else
  39. {
  40. }
  41. }
  42.  
  43. public static void main(String[] arguments) {
  44. Sound sn = new Sound();
  45. }
  46. }
Reputation Points: 113
Solved Threads: 19
Postaholic
server_crash is offline Offline
2,108 posts
since Jun 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: java uses or overrides a deprecated API??
Next Thread in Java Forum Timeline: "Problem in MultiThreading"





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC