|
-
Feb 6th, 2002, 11:25 AM
#1
Thread Starter
New Member
A prime number applet
Hey,
I need to transform this into an applet. I'm having a little trouble doing it. Please help soon. Thanks a ton!!!
import java.awt.Container;
import javax.swing.*;
class JavaPage944 {
public static void main(String arguments[]) {
int[] primes = new int[400];
int numPrimes = 0;
int x = 2;
while (numPrimes < 400) {
if (isPrime(x)) {
primes[numPrimes] = x;
numPrimes++;
}
x++;
}
System.out.println("First 400 primes:");
for (int i = 0; i < 400; i++)
System.out.print(primes[i] + " ");
}
public static boolean isPrime(int checkNumber) {
double root = Math.sqrt(checkNumber);
for (int i = 2; i <= root; i++) {
if (checkNumber % i == 0)
return false;
}
return true;
}
}
-
Feb 6th, 2002, 12:04 PM
#2
Addicted Member
I notice that you are declaring swing on line two, but not using it. Are you planning to use swing in your applet? One problem with Internet Explorer (5.x, 6.0) straight out of the box is that it will only work with JDK 1.1, but the current is JDK 1.3 and soon JDK 1.4. JDK 1.1 is pre-swing. You can use swing with IE, but in order for it to work as an applet, you have to go to Sun and download the 'Java Runtime with plugin.'
If you are making a general-purpose applet that anyone on the Internet can use, you will need to work with an older JDK. Sun offers this on their website. I think it's JDK 1.1.8. This will work with the latest versions of IE, but it doesn't have swing.
cudabean
-
Feb 7th, 2002, 10:02 PM
#3
Dazed Member
Applets arent my forte but im pretty sure you have to scrap the main method. Change your class header to class JavaPage extends Applet {. And override public void init(){} for any initialization you might want to do, and override public void start(){} also. Then within your html code you have too add the Applet tag like the following.
Code:
<HTML>
<HEAD>
<TITLE>PRIMES</TITLE>
</HEAD>
<BODY BGCOLOR="BLACK">
<APPLET codebase="C:/Java" code ="JavaPage.class" width=500 height=500>
</APPLET>
</BODY>
</HTML>
-
Feb 7th, 2002, 10:05 PM
#4
Hyperactive Member
Like the lava lamp
-
Feb 7th, 2002, 10:11 PM
#5
Dazed Member
Thanks. It gives me somthing soothing to look at while i give my self a headache trying to figure out all of this programming stuff.
-
Feb 7th, 2002, 10:16 PM
#6
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|