Purpose: Display an input form where the user enters a number (long). If an illegal character is typed, a warning beep is emitted and the character is erased. When the OK button is hit, the prime factors are calculated and displayed on an output form. When the OK button is hit there, the input dialog is shown again until the Exit button is hit.
// InOutGidlet.java Execute InOutGidlet (if you have the Sun's Wireless Toolkit (WTK) installed and the JAD extension registered. Learn how to register the JAD extension) Discussion: A simple non-optimized recursive algorithm is used. For a given number n the method primeFactor() determines the first integer divisor d by trying to divide from 2 to the square root of n. The process is repeated for n / d until this is a prime number. Each time a divisor is found, it is appended to a result string (not very efficient, but simple).
Second example: Output in a console window Purpose: Demonstrate that the sequence a(n) = (1 + 1/n)^n approaches e by writing a(n) for n = 1..100 in a console display.
Execute LimitGidlet (if you have the Sun's Wireless Toolkit (WTK) installed and the JAD extension registered. Learn how to register the JAD extension) Discussion: We use the static Float11 method pow(x, y) to calculate x^y. In order to observe the convergence smoothly, the program is executed step-by-step by clicking the OK button. Even during the running program, the cursor up/down/left/right buttons may be used to scroll the display in the four directions.
Third example: Graphics with MPanel Purpose: Same as example 2, but apply the proverb A Picture Worth A Thousand Words (numbers).
Execute GraphLimitGidlet (if you have the Sun's Wireless Toolkit (WTK) installed and the JAD extension registered. Learn how to register the JAD extension) Discussion: We use the MPanel class and are happy to forget all about device dependant pixel coordinates by defining an application specific coordinate system. Drawing text into a graphics windows is somewhat cumbersome, because we must erase the old text by painting it in white color. | ||||||||||