How to easily compile a Java midi/wav Jukebox Applet - Jan. 2002
Credit: I just want to thank to all the helpful and hardworking guys & girls on the net for all the tips, for all the freewares, sharewares, and FAQs. At least/last there are still a lot good peoples among us :-). This documentation and the java code is dedicated for those. I wrote a little nice code supporting for playing the midi/wav files directly on your website. I am not a Java applet coder or a hard coder. I coder Java only when I am hungry :-).
No more talk, let me try it! yes Ma'am: Try the Java Jukebox live
Good, I want to download it: Download Java Jukebox
The following concentrates only for the Java and internet issues.
How to compile my own Java Applet Jukebox?
The following helps you to design a new layout and show you how Java works.
Figure 1: compile java at the dos prompt
//by Tuan Nguyen 2002 Denmark JDK
/*Adding the Buttons to the Applet. There will be 3 rows, the first 2 rows with 3 buttons each. The last row has only one button, which fills 3 times at the other buttons.
Using GridBagConstraints together with GridBagLayout to manipulate the layout of the buttons on the applet-area. I could not move all the buttons to a predefine position (it might not be impossible at the moment in JDK1.2.2?). Read the GridBagLayout help for more information (jar xvf src.jar)
There are 2 lines define for button3, "c.gridwidth = GridBagConstraints.REMAINDER" is a rule, which will place button3 as the last button in a row. "gridbag.setConstraints(button3, c)" tells Java that you want to implement that rule for button3.
Button1 and button2 do not need any definitions since GridBagLayout will always place them in the center. Remember that constraint ("c.gridwidth = GridBagConstraints.REMAINDER") will also be valid for the other buttons (4,5,6,stopButton).
One the next row, you need to go back where button1 is. The "c.gridwidth = 1" does it. This must implement to button4,5,6. Button6 is the last button in row2, therefore the constraint REMAINDER.
The last row is the stopButton, I want to fill it out so it lays just below the previous two rows. As you see the c.fill is the syntax.
I hope it will help you to place new buttons on your applet. I must confess that all the constraint options do not work the way I (used to) expect.
This code uses seven midi files and one jpg file for the background (m7.mid is for the waiting/loading background music). You can change the midi/jpg file if you like.
To easy some troublesome I use the name m1-m7 in the code for midi files (for wav file: you need to change the extension in the code (.wav in steady of .mid), be aware that wav files use a lot of your bandwidth).
NB: the more midi files you want to add, the longer time the user need to wait before the applet is ready (it loads the midi files into memory). By loading the files into the memory I can achieved some "user friendly" for the Jukebox during stop/play session.
The interface AudioClip does NOT automatically stop a progress song before it plays a next one (otherwise the sound will mixed together to produce a composite). To make sure all the sound is "dead", I need to stop each of them (because I did not know which song was playing just before you choose the next one), one after one. It is quite time consume, for 6 midis (it tooks about 20-30 seconds on the local PC).
If you can find a way to "reset" the sound interface fast (please mail it to me), then you do not need to initial the clip, use "getAudioClip(getCodeBase(),"m1.mid").play();" in the actionPerformed function in steady of stop_all() and clipX.play()
Now it is time to compile the code, type again in the dos window :
If it successes there will be no errors/warning on the screen. Javac is the java compiler, it creates two class files. (hint: use –verbose to see what is going behind)
Javac creates the bytecode (the class files) which is platform independent. The Java virtual machine, which used by your browser, interprets those bytecode to the final bytecode suitable for your operative system. Meaning you can use the created class files in Unix system too.
I use JRE1.3 (remember the difference between JRE and JDK) and there are no nowadays browsers supports the JRE1.3 rendering yet, so I need to install the JRE1.3 plugin inside the user browser. It can be done by <OBJECT> tag for IE5 and <EMBED> tag for Netscape. The codebase/pluginspage takes care for download the plugin for the user browser. Adjust the width and height if you want to have another applet-area.
Turn on your speaker and enter the following at the dos prompt:
Figure 2: test the applet in the dos window
Click the buttons in the center to hear the song, the other buttons is only for "decoration". Of course you can also test it by using your internet browser. Just activate the htm file.
Hints: a good idea to see the different classes (and get to know the parameters for each class) is to unzip the src.jar file. Extract it by enter: jar xvf src.jar (just like Unix tar). The jar command is in the bin directory.
Joseph Weber’s "Special Edition Using Java, 2nd Edition" (a good book) can be found free on the net. Usehttp://www.google.com to localize it.
The PC locks everytime I visit one particular website. (IE5)
My IE5 could not handle this site http://www.iapso.org, but the Opera is OK.
It happens only for IE5. It will not help to reinstall IE5. You need to activate the "Get the ActiveX object". Open the browser preferences/security/use define. It can be a security leak so remember to flag it off afterwards. Another resolution is to use Netscape or Opera as your second browser.
------THE END Tuan Nguyen firstname.lastname@example.org