error sound in a calculctor

Reply

Join Date: Aug 2004
Posts: 2
Reputation: kelvin is an unknown quantity at this point 
Solved Threads: 0
kelvin kelvin is offline Offline
Newbie Poster

error sound in a calculctor

 
0
  #1
Sep 15th, 2004
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.
Reply With Quote Quick reply to this message  
Join Date: Jun 2003
Posts: 313
Reputation: red_evolve is on a distinguished road 
Solved Threads: 0
red_evolve's Avatar
red_evolve red_evolve is offline Offline
Posting Whiz

Re: error sound in a calculctor

 
0
  #2
Sep 15th, 2004
Hi.
The following link would probably help.
Java: Beep
"Study the past if you would define the future" - Confucius
Reply With Quote Quick reply to this message  
Join Date: Jun 2004
Posts: 2,108
Reputation: server_crash is on a distinguished road 
Solved Threads: 18
server_crash server_crash is offline Offline
Postaholic

Re: error sound in a calculctor

 
0
  #3
Sep 15th, 2004
You can always play a sound from a file like this:

  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. }
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Java Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC