Hi all, this is my first post as a user, however ive been using this site to aid me in some of my programming assignments.
I have become a little stuck with one program that i am trying to create which is a random number generator for 6 numbers. Ive done the core code so far which covers the algorithms, but i am confused on how to add code which i think covers the gui aspect of the program.
The bit im stuck on states the class should display a logo, a button and a text box to contain the six numbers. The numbers should only be generated when the button is pressed.
This is my code so far
import java.util.*;
public class LotteryNumbers
{
int[] LotteryNumbers = new int[49];
int i;
Random rgen = new Random();
//Creating an Array of 50 integers
public void createNumbers()
{
for (i=0; i < LotteryNumbers.length; i++)
{
LotteryNumbers[i] = i + 1;
}
}
//Shuffling the numbers in the array
public void shuffleNumbers()
{
for (int j=0; j < LotteryNumbers.length; i++)
{
int randomPosition = rgen.nextInt(LotteryNumbers.length);
int temp = LotteryNumbers[j];
LotteryNumbers[j] = LotteryNumbers[randomPosition];
LotteryNumbers[randomPosition] = temp;
}
}
//Sorting the numbers in the array
public void sortNumbers()
{
for(int i=0; i < LotteryNumbers.length-1; i++)
{
for(int j=0; j < LotteryNumbers.length-1-i; j++)
{
if(LotteryNumbers[j] > LotteryNumbers[j+1])
{
int temp = LotteryNumbers[j];
LotteryNumbers[j] = LotteryNumbers[j+1];
LotteryNumbers[j+1] = temp;
}
}
}
}
// Printing the numbers out
public void printnumbers( int j, int [] LotteryNumbers)
{
for (j = 0; j<= 6 && j >= 1; j++)
{
System.out.println("Lotto number: " + j + ":" + LotteryNumbers);
}
}
}