Solved

Sun.Audio.*;

Posted on 2001-06-18
2
191 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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Java virtual machine monitoring tools 3 39
copyEndy  challenge 15 55
count7 challenge 12 69
compre toata in where clue oracle 4 41
INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
The viewer will learn how to implement Singleton Design Pattern in Java.

705 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now