Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Java > Java and JDK > Java Basics
|
Java Basics General beginning Java language questions that don't fit in one of the more specific forums. Please specify what version.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Java Basics 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
 
Old March 7th, 2006, 06:49 AM
Registered User
 
Join Date: Feb 2006
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default Button doesnt play sound

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();

   }
   }







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
sound mohand Visual Basic 2005 Basics 1 November 27th, 2007 05:03 PM
play sound file kanoorani Beginning VB 6 1 July 28th, 2006 11:26 AM
Button doesnt work help john111 Java GUI 4 March 21st, 2006 05:22 PM
sound button w/actionscript nancy HTML Code Clinic 0 May 25th, 2005 01:20 PM





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