SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Hybrid View

  1. #1
    SitePoint Member
    Join Date
    Nov 2001
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    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(), "dong.au" );

    // 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 ( event.target == play ) {
    audioClip.play();
    return true;
    }
    if ( event.target == loop ) {
    audioClip.loop();
    return true;
    }
    if ( event.target == stop ) {
    audioClip.stop();
    return true;
    }
    return super.handleEvent( event );
    }
    }
    --------------------------------

  2. #2
    Xbox why have you forsaken me? moospot's Avatar
    Join Date
    Feb 2001
    Location
    Clearwater, FL
    Posts
    3,615
    Mentioned
    0 Post(s)
    Tagged
    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
    Posts
    373
    Mentioned
    0 Post(s)
    Tagged
    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 `AudioClipPlay.java'.

    2. Compile the source file using the `javac' utility which comes as part of the Java System Development Kit [1].
    Code:
    javac AudioClipPlay.java
    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.
    Code:
    <applet code="AudioClipPlay.class" width="100" height="100"></applet>

    A good tutorial covering Java applets can be found @ http://java.sun.com/docs/books/tutor...let/index.html


    [1] If you do not currently have the Java System Development Kit (SDK) installed on your system you can download the newest version from http://java.sun.com/j2se/. 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:
    Code:
    SET PATH=%PATH%;$JAVA_HOME\bin
    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:
    Code:
    <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:
    Code:
    <existing stuff>:$JAVA_HOME/bin
    - If you are not superuser edit your ~/.profile file by adding the following line at the end:
    Code:
    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.


Bookmarks

Posting Permissions

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