ptg7068951
Threads 269
52: primes.append(“First “+ quantity + “ primes:”);
53: while(numPrimes < quantity) {
54: if (isPrime(candidate)) {
55: primes.append(candidate + “ “);
56: numPrimes++;
57: }
58: candidate++;
59: }
60: }
61:
62: public static booleanisPrime(int checkNumber) {
63: doubleroot = Math.sqrt(checkNumber);
64: for (int i = 2; i <= root; i++) {
65: if (checkNumber % i == 0) {
66: returnfalse;
67: }
68: }
69: return true;
70: }
71:
72: private voidsetLookAndFeel() {
73: try {
74: UIManager.setLookAndFeel(
75: “com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel”
76: );
77: } catch(Exception exc) {
78: // ignore error
79: }
80: }
81: public static voidmain(String[] arguments) {
82: PrimeFinder fp = new PrimeFinder();
83: }
84: }
The PrimeFinderapplication displays a text field, a Display Primes button,
and a text area, as shown in Figure 19.1.
LISTING 19.1 Continued
FIGURE 19.1
Running the PrimeFinder
application.