Solved

Sun.Audio.*;

Posted on 2001-06-18
2
202 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
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…
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 …

734 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