Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Java > Other Java > Java GUI
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Java GUI Discussions specific to programming Java GUI.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Java GUI section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old March 7th, 2006, 06:53 AM
Registered User
 
Join Date: Feb 2006
Location: , , .
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default Button doesnt work help

Hi

Below is the coding that i have created i am trying to make the button play a sound when it is pressed. It worked for one button but when i put the second button it doesnt work, any help will be greatly appreciated. Thanks

import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
import java.io.*;
import java.text.*;
import java.util.*;
import java.io.PrintStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.MalformedURLException;
import java.applet.AudioClip;
import java.net.URL;

public class Panel1 extends JPanel implements ActionListener
{

   private JButton logout, open;
         //AudioClip onceClip, loopClip;
         //URL codeBase;



public Panel1()

  {
     //String [] fileTypes = {wavFile};
    //public MalformedURLException();

   //private URL("C:/JBuilder3/myprojects/untitled1/)
    //throws MalformedURLException

    logout = new JButton(" Logout ");
    logout.addActionListener(this);
    logout.setActionCommand("logout");

    open = new JButton("Hello");
    open.addActionListener(this);
    open.setActionCommand("Hello");

        JPanel controlPanel = new JPanel();
        controlPanel.add(logout);
        controlPanel.add(open);

         add(controlPanel);

  }

    public void actionPerformed( ActionEvent evt )

    {
       // play a sound before loging out


    try
    {
    if (logout == logout);
        {
         java.applet.AudioClip clip =
            java.applet.Applet.newAudioClip(new java.net.URL("C:/JBuilder3/myprojects/untitled1/logout.wav"));
         clip.play();
         }
     }
     catch (MalformedURLException ex)
     {

    {
     try
     {
     (open = open);

         {
         java.applet.AudioClip clip =
            java.applet.Applet.newAudioClip(new java.net.URL("C:/JBuilder3/myprojects/untitled1/i.wav"));
         clip.play();
         }
     }
     catch (MalformedURLException pex)
     {

    }
    }
    }
    }

    public static void main(String s[]) {
        WindowListener l = new WindowAdapter() {
            public void windowClosing(WindowEvent e) {System.exit(0);}
        };
        JFrame f = new JFrame("Panel");
        f.addWindowListener(l);
        f.getContentPane().add(new Panel1());
        //f.setSize(new Dimension(400,100));
        f.show();

   }
   }

Reply With Quote
  #2 (permalink)  
Old March 11th, 2006, 11:55 AM
Registered User
 
Join Date: Feb 2006
Location: , , .
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

anyone?

Reply With Quote
  #3 (permalink)  
Old March 16th, 2006, 10:12 AM
Registered User
 
Join Date: Mar 2006
Location: Melbourne, Florida, USA.
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

It did not work for me either, but when I tried to use the beep method in the package Toolkit before

java.applet.AudioClip clip =
                   java.applet.Applet.newAudioClip(new java.net.URL("C:/JBuilder3/myprojects/untitled1/logout.wav"));
                   clip.play();

then it works.
Reply With Quote
  #4 (permalink)  
Old March 18th, 2006, 01:17 PM
Registered User
 
Join Date: Feb 2006
Location: , , .
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi

I dont understand what you mean could you explain what you used. Thanks.

Reply With Quote
  #5 (permalink)  
Old March 21st, 2006, 05:22 PM
Registered User
 
Join Date: Mar 2006
Location: Melbourne, Florida, USA.
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

John,
    I believe that the parameter you passed to Applet.newAudioClip is not a URL. Here is what I tried, and it works

url = new URL("file:///C:/welcome.wave");
clip = Applet.netAudioClip(url);
clip.play();

This should work. Let me know what you think.
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Link button in nested grids clcik doesnt work fir RaghaSM ASP.NET 2.0 Basics 1 June 26th, 2008 12:05 AM
c:out doesnt work tllcll JSP Basics 1 November 1st, 2007 03:15 AM
xsl:key doesnt work cristtiah XSLT 11 May 24th, 2006 09:57 AM
ContainsValue doesnt work demitry Generics 1 November 21st, 2005 05:29 PM
WHY DOESNT THIS WORK vb certified Pro VB.NET 2002/2003 5 August 1st, 2005 11:08 PM



All times are GMT -4. The time now is 04:13 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.