Solved

Sun.Audio.*;

Posted on 2001-06-18
2
196 Views
Last Modified: 2010-04-16
I want to use the sun.audio.* classes in my applet.
However, I do not want to use: import sun.audio.*;, because not all browsers have the sun.audio.*-classes. Rather I want to use:

try {
  audioStream = Class.forName(sun.audio.AudioStream);
  audioPlayer = Class.forName(sun.audio.AudioPlayer);
}
catch {}

However, when I do this, I can obviously not declare a public variable: public AudioPlayer audioPlayer;, because the package has not yet been imported.

Any suggestions for how to deal with this?
0
Comment
Question by:terjeg
2 Comments
 
LVL 3

Accepted Solution

by:
superschlonz earned 200 total points
ID: 6203735
Create an interface with the needed methods, impement it in a class
which does these audio things like this:

public interface AudioInterface
{
  public void play();
}

public class AudioFacade implements AudioInterface
{
  AudioStream stream;
  AudioPlayer player;
  public AudioFacade()
  {
   stream = new AudioStrem( ... );
   player = new AudioPlayer( ... );
  }
  public void play()
  {
    player.play();
  }
}

and use it like this:

AudioInterface audio = null;
try {
  audio = class.forName( "AudioFacade").newInstance();
} catch( Throwable t ) {
  // could not create...
}
if( audio != null )
{
  audio.play();
}

This way you have no direct reference to the AudioFacade and your applet
doesn't need those classes for beeing loaded.
0
 
LVL 14

Expert Comment

by:sudhakar_koundinya
ID: 8950801


No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:


--  points to superschlonz


Please leave any comments here within the next seven days.
 
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
 
sudhakar_koundinya
EE Cleanup Volunteer
---------------------
If you feel that your question was not properly addressed, or that none of the comments received were appropriate answers, please post your concern in THIS thread.
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

786 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question