1

I am new to Java Applets.I installed the JMStudio and added all the .jar files in the project but still not working.

I have installed the .jar Files in the the Project>Properties>Java Build Path>Libraries

Here`s My Program:

import java.applet.*;
import java.awt.Button;
import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class design extends Applet implements ActionListener
{
    Button play,stop;
    AudioClip audioClip;
    public void init(){
      play = new Button("  Play in Loop  ");
      add(play);
      play.addActionListener(this);
      stop = new Button("  Stop  ");
      add(stop);
      stop.addActionListener(this);
      audioClip = getAudioClip(getCodeBase(), "About Time.mid");
   }

@Override
public void actionPerformed(ActionEvent ae) {
    Button source = (Button)ae.getSource();
      if (source.getLabel() == "  Play in Loop  "){
         audioClip.play();
      }  
      else if(source.getLabel() == "  Stop  "){
         audioClip.stop();
      }
   }

}

And here`s the errors

java.lang.IllegalAccessError: tried to access class com.sun.media.sound.Printer from class com.sun.media.sound.HeadspaceSoundbank
at com.sun.media.sound.HeadspaceSoundbank.<init>(HeadspaceSoundbank.java:81)
at com.sun.media.sound.HsbParser.getSoundbank(HsbParser.java:69)
at javax.sound.midi.MidiSystem.getSoundbank(MidiSystem.java:535)
at com.sun.media.sound.SoftSynthesizer.getDefaultSoundbank(SoftSynthesizer.java:711)
at com.sun.media.sound.SoftSynthesizer.openStream(SoftSynthesizer.java:1150)
at com.sun.media.sound.SoftMidiAudioFileReader.getAudioInputStream(SoftMidiAudioFileReader.java:73)
at com.sun.media.sound.SoftMidiAudioFileReader.getAudioInputStream(SoftMidiAudioFileReader.java:145)
at javax.sound.sampled.AudioSystem.getAudioInputStream(AudioSystem.java:1113)
at com.sun.media.sound.JavaSoundAudioClip.<init>(JavaSoundAudioClip.java:102)
at sun.applet.AppletAudioClip.createAppletAudioClip(AppletAudioClip.java:125)
at sun.applet.AppletAudioClip.<init>(AppletAudioClip.java:66)
at sun.applet.AppletViewer.getAudioClip(AppletViewer.java:383)
at java.applet.Applet.getAudioClip(Applet.java:329)
at java.applet.Applet.getAudioClip(Applet.java:349)
at com.design.init(design.java:20)
at sun.applet.AppletPanel.run(AppletPanel.java:434)
at java.lang.Thread.run(Thread.java:745)

I guess the problem might be in the installation of JMF....but i don`t know exactly where i am wrong.

Please someone tell the exact method to run JMF in eclipse.

Mukul
  • 7
  • 1
  • 1) Why code an applet? If it is due to the teacher specifying it, please refer them to [Why CS teachers should **stop** teaching Java applets](http://programmers.blogoverflow.com/2013/05/why-cs-teachers-should-stop-teaching-java-applets/). 2) Why use AWT? See [this answer](http://stackoverflow.com/questions/6255106/java-gui-listeners-without-awt/6255978#6255978) for many good reasons to abandon AWT using components in favor of Swing. 3) You don't need JMF to play a MIDI file. [Java Sound](http://stackoverflow.com/tags/javasound/info) could do that since Java 1.3! – Andrew Thompson Aug 25 '15 at 12:14

1 Answers1

0

Seems a library conflict. Make sure that in the buildpath of eclipse you don't have different versions of the library. Take a look also other libraries that are in the classpath. When running an application in eclipse or other ide you can see the -D variables and -classpath that is used by the JVM.

Edit: I have launched the applet from eclipse using jre 8 without any extra library in the build path.

java_build_path

and I got two buttons after launching the applet in eclipse:

Applet image

maybe changing the jre and deleting jmf libraries you can execute the applet.

regards

Alex M
  • 471
  • 4
  • 22