Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Java > Other Java > Java GUI
| 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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #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();

   }
   }

  #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?

  #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.
  #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.

  #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.


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





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.