Java Programming Issues


Windows Programming

Java program is cross-platform. An Application on the web page is called a Java applet. Java applet is a window application. Thus, understanding the windows environment is necessary. Execution of windows program is event-driven that means the response of the program is determined by the user's actions. For example, a program would redraw the interface when the user changes the size of the window. Or, the program would generate a message if the user tries to make an illegal command. The most important thing is that the programmer has no idea of the order of the program execution.


Windows Update

A Java applet should handle the events from the operating system. For example, if the window of Netscape is maximized, the centered controls (buttons, textfields, graphics, etc) inside the applet is not centered anymore. The applet should be able to relocate the controls such that they are centered. This is not handled by the Java interpreter or the windows manager automatically. The programmer needs to write the codes to handle this. For example, the program should have functions that could handle window's update when the window is activiated. Each graphical element should be updated, too.

Interface

Java Graphical User Interface (GUI) provides common user controls like buttons, combo boxes, textfields, etc. First of all, you need a container to hold the controls. A container can also be contained by another container, so that you can design your user interface in different pieces of containers and combine them in a final container. For example, I used this approach to create my user interface. I created the Function panel (container), the Filter panel, Button panel and Screen panel separately ,and I added them onto Main panel. That makes the management of the user interface easier if there is a lot of controls in one window.


Graphics

An image requires special handling. First the image needs a container to become visible. I used the double buffering technique to handle the images. What double buffering does is to create images in a buffer. The image is displayed only when it is completely made. Using this approach the image is updated smoother than if it were updated directly on the user interface. Double buffering is the technique used for animation. With proper use of threads, the function on the screen could have nice motions.

In this project, there are occasions when the elements of a graph data are undefined. When the user tries to divide a sine function with a cosine function, it would yield undefined values whenever cosine the denominator is zero. Therefore, I trapped this situation by ignoring undefined value. As a result, you see discontinuities on a tangent waveform.


Sound

Java has an non-published audio library named sun.audio which contains useful functions to handle au conversion, sound clip and sound samples. It also allows sound device to play sound continuously. Although there is no formal documentation about the use of this library, through trial and error I was able to understand the functions. After trials, I found out that valid sound samples must be positive and be within 0 and 60. When the samples exceed or drop below the range, the sound quality becomes unstable and unpredictable. Therefore, I wrote a function to trap that problem. When the sound samples are undefined, they will be set to zero. When the samples are too large, their values are reduced and biased until they become valid samples. The function is a member function of Signal Class, and its declaration is:


In fact, the Java audio library handles the au conversion internally. The sound buffer contains the amplitudes of a waveform. When the user enables the sound player to play, the player looks up the values in the buffer, performs au conversion internally, and plays the sound. The player looks up the buffer continuously, so that it will play different sound when you change the values in the buffer. However, you need to setup the player in the WaveDisplay class as follows:

Then, here shows how to control the player

Start the sound player:

Stop the sound player:

If you are interested in the inside of the library, please go to www.sun.com or java.sun.com