Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

GUI interface

Status
Not open for further replies.

M626

Programmer
Joined
Mar 13, 2002
Messages
299
I need to Get this code onto a GUI interface(an applet) any anyone show me what I need to add to do this. I have the html code to call the class file I just need to know what I need to add to this code.
Thanks,


import javax.swing.*;

public class ArrayPrime {

public static void main(String args[]) {
int num1, sq; // Creates int variable
String val; // Creates String variables

val = JOptionPane.showInputDialog (" Enter a number from 1 to 1000: " ); //get's number for array

num1 = Integer.parseInt( val ); //changes what's inputed into a int value

while ( num1 < 3 || num1 > 1000 ) { //makes sure the value is in the proper range
val = JOptionPane.showInputDialog (&quot; Please only enter a number between 3 to 1000, to get prime numbers.&quot; ); //error check to make sure correct value entered

num1 = Integer.parseInt( val ); //changes what's inputed into a int value
}



boolean[] isprime = new boolean[num1+1]; //creates array with num1 equal to input

// Assume all numbers are primes, until proven wrong
for(int count = 2; count <= num1; count++) //make all numbers initaially prime
isprime[count] = true; //makes all array element initially prime



sq = (int) Math.ceil(Math.sqrt(num1)); // finds square root of value inputed by to determin what number to factor


for(int count2 = 0; count2 <= sq; count2++) { //make all the multiples of a prime number set to false
if (isprime[count2] == true)
for(int count3 = 2*count2; count3 <= num1; count3 += count2) // loop through its multiples
isprime[count3] = false; // changes all multiples of prime numbers into false so they're noted as &quot;not prime&quot;.
}


for( int count4= 2; count4 <= num1; count4++) //goes through all numbers that were searched to print out all that are prime
if (isprime[count4] == true) //checks if the array element is true

System.out.print(count4 + &quot; &quot;); //outputs that value

System.exit(0);
}
}
 
I know I need to extend JApplet but the rest I don't know. Please help?
 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Sponsor

Back
Top