SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Hybrid View

  1. #1
    SitePoint Member
    Join Date
    Nov 2001
    0 Post(s)
    0 Thread(s)

    Java Applet Help

    Forgive me, I am new to this...
    How do I insert this applet (seen below)into my web page to get it to work?
    Are there variables I need to fill in?
    Is there other code to insert to get this code to work?
    Any help would be greatly appreciated. Thanks
    import java.applet.AudioClip;
    import java.awt.Button;

    public class AudioClipPlay extends java.applet.Applet {
    AudioClip audioClip;
    Button play, loop, stop;

    // Applet role
    public void init() {
    // Get sound.
    audioClip = getAudioClip( getCodeBase(), "" );

    // Create GUI.
    add( play = new Button( "play" ) );
    add( loop = new Button( "loop" ) );
    add( stop = new Button( "stop" ) );

    // Component role (1.02 event model)
    public boolean handleEvent( Event event ) {
    if ( == play ) {;
    return true;
    if ( == loop ) {
    return true;
    if ( == stop ) {
    return true;
    return super.handleEvent( event );

  2. #2
    Xbox why have you forsaken me? moospot's Avatar
    Join Date
    Feb 2001
    Clearwater, FL
    0 Post(s)
    0 Thread(s)
    Can I ask where you got this code from? I thought you had to compile Java code before you could run it on a web page?

  3. #3
    Are you ready for BSD? Marshall's Avatar
    Join Date
    Dec 2001
    0 Post(s)
    0 Thread(s)
    There are four basic steps required to compile a Java applet and include it in an HTML document.

    1. Place the source code for the Java applet in a separate file with the same name as the class and the `.java' file extension. In your case you would name this source file `'.

    2. Compile the source file using the `javac' utility which comes as part of the Java System Development Kit [1].
    Assuming you recieve no error messages while compiling and the AudioClipPlay.class file is created...

    3. Place the AudioClipPlay.class file in the same Web-accessible directory as your HTML code.

    4. Add an <applet> parameter within your HTML document to load the class file.
    <applet code="AudioClipPlay.class" width="100" height="100"></applet>

    A good tutorial covering Java applets can be found @

    [1] If you do not currently have the Java System Development Kit (SDK) installed on your system you can download the newest version from After installation you'll want to place the `$JAVA_HOME/bin' directory in your system PATH, where `$JAVA_HOME' is replaced with the directory into which the SDK was installed. By doing this all of the binary executables located in the /bin directory, including the `javac' utility, will be accessible from any directory on your system.

    To perminantly modify your system PATH settings...

    On MS Windows 9x/2000:
    - Edit the c:\autoexec.bat file and add the following parameter on a new line at the end:
    A system restart is required for these changes to take effect.

    On MS Windows XP:
    - Go `Start Menu>Settings>Control Panel>System Properties>Environment Variables' and edit the PATH value by adding the following value at the end of the existing string:
    <existing stuff>;$JAVA_HOME\bin
    On most Unix/Linux systems:
    - If you have superuser privledges, edit the /etc/profile file and modify the existing PATH value by adding the following string at the end:
    <existing stuff>:$JAVA_HOME/bin
    - If you are not superuser edit your ~/.profile file by adding the following line at the end:
    export PATH="${PATH}:$JAVA_HOME/bin"
    Remember in all cases to replace `$JAVA_HOME' with your SDK installation directory.

    To compile your class file after completing the above installation you'd open a Console window (on MS Windows) or a shell session (on *nix) and use the `cd' command to change to the directory in which your .java source file is located. You can then execute the javac command as shown in step 2.

    - Marshall
    Last edited by Marshall; Dec 14, 2001 at 18:05.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts