Solved

Sun.Audio.*;

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

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Java: The Public Class Main 4 46
Selenium docs api java index 3 69
Html Table Looping (part 2) 5 35
Java array sort 10 35
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 first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
The viewer will learn how to implement Singleton Design Pattern in Java.

730 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