Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 03-28-2008, 08:26 PM
Member
 
Join Date: Mar 2008
Posts: 3
shanky_sanks is on a distinguished road
Problem in adding sound.
I cannot paste the entire code since its too big.But i can provide with relevant stuff.

Code:
import java.net.*; import java.applet.*; class pawn extends chesspiece { public pawn(int c) { player_id=c; piece_code=6; } public int get_id() { return player_id; } public int get_code() { return piece_code; } public boolean validity(int x1,int y1,int x2,int y2,chesspiece p[][]) { AudioClip au1; URL codeBase = getCodeBase(); au1 = getAudioClip (codeBase, "sounds/pawn.WAV"); if(player_id==0) { if(p[x2][y2]==null)//for moving ahead { if(y1==1) { if(x1==x2&&y2-y1==1||x1==x2&&y2-y1==2) { au1.play(); return true; } } else { if(x1==x2&&y2-y1==1) { au1.play(); return true; } } } else if(p[x2][y2]!=null)//for killing { if((Math.abs(x2-x1)==1&&y2-y1==1)&&(p[x2][y2].get_id()!=p[x1][y1].get_id())) { au1.play(); return true; } else return false; } else { if(p[x2][y2]==null) { if(y1==6) { if(x1==x2&&y1-y2==1||x1==x2&&y1-y2==2) { au1.play(); return true; } } else { if(x1==x2&&y1-y2==1) { au1.play(); return true; } } } else if(p[x2][y2]!=null) { if(Math.abs(x2-x1)==1&&y1-y2==1&&p[x1][y1].get_id()!=p[x2][y2].get_id()) { au1.play(); return true; } } else return false ; } return false; } return false; }
From what I have read on the internet I can tell that since the getCodeBase() and getAudioClip() are in a class and there are various classes so it is not able to get the functions from the applet package. It gives the following errors

cannot find symbol method getCodeBase()
cannot find symbol method getAudioClip(java.net.URL,java.lang.String)
Please Help.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 03-29-2008, 06:20 AM
Member
 
Join Date: Mar 2008
Posts: 19
jamesfrize is on a distinguished road
Sounds
the getCodeBase() method can only be called in the main applet/Japplet. From there you would have to pass it to the class you wanna use it in. You can use:

AudioClip ac = getAudioClip(getCodeBase(), file); //load sound file
ac.play(); //play file, you can also have ac.stop(); & ac.loop();

'file' is just a string with the file name stored in it- "yourSound.wav"
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 03-29-2008, 06:26 AM
Member
 
Join Date: Mar 2008
Posts: 19
jamesfrize is on a distinguished road
maybe you could add the sound to the top of:

public boolean validity(int x1,int y1,int x2,int y2,chesspiece p[][],AudioClip ac)
{
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 03-29-2008, 08:19 PM
Member
 
Join Date: Mar 2008
Posts: 3
shanky_sanks is on a distinguished road
thanx for the reply but I have one more problem that I am using this function validity a lot number of times in my code so I cant add the 'ac'.
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 03-29-2008, 08:22 PM
Member
 
Join Date: Mar 2008
Posts: 3
shanky_sanks is on a distinguished road
Quote:
Originally Posted by jamesfrize View Post
the getCodeBase() method can only be called in the main applet/Japplet. From there you would have to pass it to the class you wanna use it in.
Can you please be a bit precise with some example if you have or can provide.
Bookmark Post in Technorati
Reply With Quote
  #6 (permalink)  
Old 03-29-2008, 10:15 PM
Member
 
Join Date: Mar 2008
Posts: 19
jamesfrize is on a distinguished road
example
I can give you the code for my stupidly simple animation button. I use it as the enter screen for my personal website. When you click on the applet it plays back a sound and opens my main web page.

Code:
import java.awt.*; import javax.swing.*; import java.applet.*; import java.awt.event.*; import java.net.*; public class index extends JApplet implements ActionListener { private MediaTracker mt; private Image enter; private Image enter2; private Image enter3; private Image enter4; private Image enter5; private Image enter6; private Timer timer; private int delay = 120; private int frame = 1; private String file = "opened.wav"; public void init() { setBounds(0,0,640,480); timer = new Timer(delay, this); mt = new MediaTracker(this); enter = getImage(getCodeBase(), "sonodrome1.jpg"); mt.addImage(enter,1); enter2 = getImage(getCodeBase(), "sonodrome2.jpg"); mt.addImage(enter2,1); enter3 = getImage(getCodeBase(), "sonodrome3.jpg"); mt.addImage(enter3,1); enter4 = getImage(getCodeBase(), "sonodrome4.jpg"); mt.addImage(enter4,1); enter5 = getImage(getCodeBase(), "sonodrome5.jpg"); mt.addImage(enter5,1); enter6 = getImage(getCodeBase(), "sonodrome6.jpg"); mt.addImage(enter6,1); timer.start(); addMouseListener ////mouse clicks ( new MouseAdapter() { public void mousePressed(MouseEvent me) { System.out.println("Mouse!"); AudioClip ac = getAudioClip(getCodeBase(), file); ///Locate file ac.play(); /////Playback try { AppletContext a = getAppletContext(); URL u = new URL("http://jamesfrize.43host.info/sonodrome.html"); a.showDocument(u,"_self"); } catch (Exception e) { System.out.println("Page Url Incorrect"); } } } ); try { mt.waitForAll(); } catch (InterruptedException e) {} } public void paint(Graphics g) { frame = (frame + 1); if(frame == 1) { g.drawImage(enter,0,0,this); } else if(frame == 2) { g.drawImage(enter2,0,0,this); } else if(frame == 3) { g.drawImage(enter3,0,0,this); } else if(frame == 4) { g.drawImage(enter4,0,0,this); } else if(frame == 5) { g.drawImage(enter5,0,0,this); } else if(frame == 6) { g.drawImage(enter6,0,0,this); } else if(frame == 7) { g.drawImage(enter5,0,0,this); } else if(frame == 8) { g.drawImage(enter4,0,0,this); } else if(frame == 9) { g.drawImage(enter3,0,0,this); } else if(frame == 10) { g.drawImage(enter2,0,0,this); frame = 2; } } public static void main (String args[]) { index img1 = new index(); img1.setVisible(true); } public void actionPerformed(ActionEvent e) { repaint(); } }
Hope this is of some help. Here is a link to see the applet in action-Sonodrome
Bookmark Post in Technorati
Reply With Quote
  #7 (permalink)  
Old 03-29-2008, 10:37 PM
Member
 
Join Date: Mar 2008
Posts: 19
jamesfrize is on a distinguished road
I'm not as sure about passing the audio file outside the main class. I have not had the chance to try this code on a server. But it should work like this:

import java.awt.*;
import javax.swing.*;
import java.applet.*;
import java.awt.event.*;
import java.net.*;

public class index extends JApplet
{
private String file = "opened.wav";
public AudioClip ac;

public void init()
{
setBounds(0,0,640,480);
ac = getAudioClip(getCodeBase(), file); ///Locate file

addMouseListener ////mouse clicks
(
new MouseAdapter()
{
public void mousePressed(MouseEvent me)
{
System.out.println("Mouse!");
play(ac);// run playback method
}
}
);
}

public void play(AudioClip aClip) //Arguments that are required
{
aClip.play(); /////Playback
}
}
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
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

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
add sound to my applet anotsu Java Applets 4 03-25-2008 01:26 AM
Re-playing sound JSK CLDC and MIDP 0 02-06-2008 01:34 PM
applet sound marco Java Applets 1 09-29-2007 12:31 AM
Sound in applet Java toby Java Applets 1 08-07-2007 07:52 AM
Applets having sound peiceonly Java Applets 2 03-31-2007 11:55 AM


All times are GMT +3. The time now is 08:25 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org