Exercise 12: Odds and Ends

Home/Java - Tutorial/Java - Applet/Exercise 12: Odds and Ends
Exercise 12: Odds and Ends 2015-12-04T18:00:03+00:00

[ Home | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 ]

Exercise 12: Odds and Ends

Audio

To play audio files, use Applet.play(). Java 1.1 only supports Sun Audio (.au) files, or specifically, 8 bit, u-law, 8000 Hz, one-channel Sun format. Both Applet.play() and AudioClip.play() are non-blocking: they return immediately after starting the playback of the audio file. Try here for an example.

Applet Info

You can embed information about your applet inside itself by defining getAppletInfo() and getParameterInfo().

Debugging Tips

If you’re having trouble understanding what your applet is doing (or not doing), use System.out.println() and showStatus() to print out the values of variables and information about where the program is.

Browsers won’t normally reload applets after they’ve been loaded once. If you test an applet inside your browser, and then modify the applet’s source code and recompile, simply reloading the webpage in your browser isn’t enough to view the new applet. You’ll have to exit and restart your browser. To avoid this nuisance, do initial testing of applets with appletviewer rather than a web browser.

Conditional Compilation

In C, blocks of code can be conditionally compiled using #define flags thus:

Java is not as flexible, but allows for something that is sometimes just as good:

The final keyword means the variable is constant, so unless your compiler’s optimizer is brain-dead, it should prune out the conditional and the unreachable block of code.


 

(Download the below file: ArchimedianSpiral.java)