0% found this document useful (0 votes)
63 views3 pages

Lot To Number Generator

This Java code defines a LottoUI class that generates random lottery numbers. It uses Swing components like JFrame and JTextField. There are methods to generate numbers for different lottery types by randomly shuffling arrays and setting the text of number fields. Timers are used to repeatedly call the generation methods to display rolling numbers. Buttons trigger the different generation logic and configure the UI elements.

Uploaded by

Ryanne Christine
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
63 views3 pages

Lot To Number Generator

This Java code defines a LottoUI class that generates random lottery numbers. It uses Swing components like JFrame and JTextField. There are methods to generate numbers for different lottery types by randomly shuffling arrays and setting the text of number fields. Timers are used to repeatedly call the generation methods to display rolling numbers. Buttons trigger the different generation logic and configure the UI elements.

Uploaded by

Ryanne Christine
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

package my.

lotto;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Random;
import javax.swing.Timer;

public class LottoUI extends javax.swing.JFrame {

Timer timer, timer1;


int lottotype;
int loopnum;

void generate_num(){
int[] lottonum = new int [lottotype];
Random rand = new Random();

for(int i = 1; i <lottonum.length; i++){


lottonum[i] = i;
}
for(int b = 1; b <lottonum.length; b++){
int randomIndexToSwap = rand.nextInt(lottonum.length);
if(randomIndexToSwap == 0){
randomIndexToSwap++;
}
int temp = lottonum[randomIndexToSwap];
lottonum[randomIndexToSwap] = lottonum[b];
lottonum[b] = temp;
}
jTextField1.setText(Integer.toString(lottonum[1]));
jTextField2.setText(Integer.toString(lottonum[2]));
jTextField3.setText(Integer.toString(lottonum[3]));
jTextField4.setText(Integer.toString(lottonum[4]));
jTextField5.setText(Integer.toString(lottonum[5]));
jTextField6.setText(Integer.toString(lottonum[6]));
loopnum++;
if(loopnum == 100){
timer.stop();
}
}
void timeraction () {
timer = new Timer (10, new ActionListener () {
@Override

public void actionPerformed (ActionEvent e) {


generate_num();
}
});
}

void sixdigit(){
Random rand = new Random();
int text1,text2,text3,text4,text5,text6;

for (int len=1; len<=6; len++) {


text1 = rand.nextInt(10);
text2 = rand.nextInt(10);
text3 = rand.nextInt(10);
text4 = rand.nextInt(10);
text5 = rand.nextInt(10);
text6 = rand.nextInt(10);

jTextField1.setText(Integer.toString (text1));
jTextField2.setText(Integer.toString (text2));
jTextField3.setText(Integer.toString (text3));
jTextField4.setText(Integer.toString (text4));
jTextField5.setText(Integer.toString (text5));
jTextField6.setText(Integer.toString (text6));
loopnum++;
if(loopnum==100) {
timer.stop();
}
}
}

void timeraction1 () {
timer = new Timer (10, new ActionListener() {
@Override
public void actionPerformed (ActionEvent ae) {
sixdigit();
}
});
}

public LottoUI() {
initComponents();
}

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {

lottotype = 43;
timeraction();
loopnum=0;
timer.start();
jLabel2.setIcon(new
javax.swing.ImageIcon(getClass().getResource("/my/lotto/pics/6-42.png")));
jLabel3.setText("6/42 Generated Number");

private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {

lottotype = 46;
timeraction();
loopnum=0;
timer.start();
jLabel2.setIcon(new
javax.swing.ImageIcon(getClass().getResource("/my/lotto/pics/6-45.png")));
jLabel3.setText("6/45 Generated Number");

private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {

lottotype = 50;
timeraction();
loopnum=0;
timer.start();
jLabel2.setIcon(new
javax.swing.ImageIcon(getClass().getResource("/my/lotto/pics/6-49.png")));
jLabel3.setText("6/49 Generated Number");

private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {

lottotype = 56;
timeraction();
loopnum=0;
timer.start();
jLabel2.setIcon(new
javax.swing.ImageIcon(getClass().getResource("/my/lotto/pics/6-55.png")));
jLabel3.setText("6/55 Generated Number");

private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {

lottotype = 59;
timeraction();
loopnum=0;
timer.start();
jLabel2.setIcon(new
javax.swing.ImageIcon(getClass().getResource("/my/lotto/pics/6-58.png")));
jLabel3.setText("6/58 Generated Number");

private void jButton6ActionPerformed(java.awt.event.ActionEvent evt) {

sixdigit();
timeraction1();
loopnum=0;
timer.start();
jLabel2.setIcon(new
javax.swing.ImageIcon(getClass().getResource("/my/lotto/pics/6-digit.png")));
jLabel3.setText("6-digit Generated Number");

You might also like