/**
* @(#)lottoDraw.java
*
*
* @author
* @version 1.00 2012/12/1
*/
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class lottoDraw extends JFrame implements ActionListener, ItemListener
{
JCheckBox b0,b1,b2,b3,b4,b5,b6,b7,b8,b9,b10,b11,b12,b13,b14,b15,b16,b17,b18,b19,b20,b21,b22,b23,b24,b25,b26,b27,b28,b29,b30;
JLabel lottoName,result,pickedNumbers,reward;
JButton draw,exit;
JPanel p1,p2,p3,p4,p5,p6,p7,p8;
JFrame myFrame = new JFrame("Lotto");
GridLayout layout = new GridLayout(1,1);
int resultNum1 = 0 + (int)(Math.random() * ((29 - 0) + 1));
int resultNum2 = 0 + (int)(Math.random() * ((29 - 0) + 1));
int resultNum3 = 0 + (int)(Math.random() * ((29 - 0) + 1));
int resultNum4 = 0 + (int)(Math.random() * ((29 - 0) + 1));
int resultNum5 = 0 + (int)(Math.random() * ((29 - 0) + 1));
int resultNum6 = 0 + (int)(Math.random() * ((29 - 0) + 1));
int check;
int num [] = {0,0,0,0,0,0};
int turn [] = {0,0,0,0,0,0};
public lottoDraw()
{
myFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
myFrame.setSize(700, 500);
myFrame.setVisible(true);
myFrame.setLayout(new GridLayout(8,1));
p1 = new JPanel(new FlowLayout(FlowLayout.CENTER));
p2 = new JPanel(new FlowLayout(FlowLayout.CENTER));
p3 = new JPanel(new FlowLayout(FlowLayout.CENTER));
p4 = new JPanel(new FlowLayout(FlowLayout.CENTER));
p5 = new JPanel(layout);
p6 = new JPanel(layout);
p7 = new JPanel(layout);
p8 = new JPanel(layout);
b0 = new JCheckBox("0");
b1 = new JCheckBox("1");
b2 = new JCheckBox("2");
b3 = new JCheckBox("3");
b4 = new JCheckBox("4");
b5 = new JCheckBox("5");
b6 = new JCheckBox("6");
b7 = new JCheckBox("7");
b8 = new JCheckBox("8");
b9 = new JCheckBox("9");
b10 = new JCheckBox("10");
b11 = new JCheckBox("11");
b12 = new JCheckBox("12");
b13 = new JCheckBox("13");
b14 = new JCheckBox("14");
b15 = new JCheckBox("15");
b16 = new JCheckBox("16");
b17 = new JCheckBox("17");
b18 = new JCheckBox("18");
b19 = new JCheckBox("19");
b20 = new JCheckBox("20");
b21 = new JCheckBox("21");
b22 = new JCheckBox("22");
b23 = new JCheckBox("23");
b24 = new JCheckBox("24");
b25 = new JCheckBox("25");
b26 = new JCheckBox("26");
b27 = new JCheckBox("27");
b28 = new JCheckBox("28");
b29 = new JCheckBox("29");
b30 = new JCheckBox("30");
lottoName = new JLabel("WIN WIN WIN");
result = new JLabel();
pickedNumbers = new JLabel();
reward = new JLabel();
draw = new JButton("Draw");
exit = new JButton("Exit");
myFrame.add(p1);
myFrame.add(p2);
myFrame.add(p3);
myFrame.add(p4);
myFrame.add(p5);
myFrame.add(p6);
myFrame.add(p7);
myFrame.add(p8);
p1.add(lottoName);
p2.add(pickedNumbers);
p3.add(result);
p4.add(reward);
p5.add(b0);
p5.add(b1);
p5.add(b2);
p5.add(b3);
p5.add(b4);
p5.add(b5);
p5.add(b6);
p5.add(b7);
p5.add(b8);
p5.add(b9);
p5.add(b10);
p6.add(b11);
p6.add(b12);
p6.add(b13);
p6.add(b14);
p6.add(b15);
p6.add(b16);
p6.add(b17);
p6.add(b18);
p6.add(b19);
p6.add(b20);
p6.add(b21);
p7.add(b22);
p7.add(b23);
p7.add(b24);
p7.add(b24);
p7.add(b25);
p7.add(b26);
p7.add(b27);
p7.add(b28);
p7.add(b29);
p7.add(b30);
p8.add(draw);
p8.add(exit);
b0.addItemListener(this);
b1.addItemListener(this);
b2.addItemListener(this);
b3.addItemListener(this);
b4.addItemListener(this);
b5.addItemListener(this);
b6.addItemListener(this);
b7.addItemListener(this);
b8.addItemListener(this);
b9.addItemListener(this);
b10.addItemListener(this);
b11.addItemListener(this);
b12.addItemListener(this);
b13.addItemListener(this);
b14.addItemListener(this);
b15.addItemListener(this);
b16.addItemListener(this);
b17.addItemListener(this);
b18.addItemListener(this);
b19.addItemListener(this);
b20.addItemListener(this);
b21.addItemListener(this);
b22.addItemListener(this);
b23.addItemListener(this);
b24.addItemListener(this);
b25.addItemListener(this);
b26.addItemListener(this);
b27.addItemListener(this);
b28.addItemListener(this);
b29.addItemListener(this);
b30.addItemListener(this);
draw.addActionListener(this);
}
public void itemStateChanged(ItemEvent e)
{
Object source = e.getSource();
Object select = e.getStateChange();
for(int x=0;x<num.length;x++)
{
if(source == b0)
{
if(select == ItemEvent.SELECTED)
{
num[x] = 0;
check++;
break;
}
else
{
num[x] = 0;
check--;
break;
}
}
if(source == b1)
{
if(select == ItemEvent.SELECTED)
{
num[x] = 1;
check++;
break;
}
else
{
num[x] = 0;
check--;
break;
}
}
if(source == b2)
{
if(select == ItemEvent.SELECTED)
{
num[x] = 2;
check++;
break;
}
else
{
num[x] = 0;
check--;
break;
}
}
if(source == b3)
{
if(select == ItemEvent.SELECTED)
{
num[x] = 3;
check++;
break;
}
else
{
num[x] = 0;
check--;
break;
}
}
if(source == b4)
{
if(select == ItemEvent.SELECTED)
{
num[x] = 4;
check++;
break;
}
else
{
num[x] = 0;
check--;
break;
}
}
if(source == b5)
{
if(select == ItemEvent.SELECTED)
{
num[x] = 5;
check++;
break;
}
else
{
num[x] = 0;
check--;
break;
}
}
if(source == b6)
{
if(select == ItemEvent.SELECTED)
{
num[x] = 6;
check++;
break;
}
else
{
num[x] = 0;
check--;
break;
}
}
if(source == b7)
{
if(select == ItemEvent.SELECTED)
{
num[x] = 7;
check++;
break;
}
else
{
num[x] = 0;
check--;
break;
}
}
if(source == b8)
{
if(select == ItemEvent.SELECTED)
{
num[x] = 8;
check++;
break;
}
else
{
num[x] = 0;
check--;
break;
}
}
if(source == b9)
{
if(select == ItemEvent.SELECTED)
{
num[x] = 9;
check++;
break;
}
else
{
num[x] = 0;
check--;
break;
}
}
if(source == b10)
{
if(select == ItemEvent.SELECTED)
{
num[x] = 10;
check++;
break;
}
else
{
num[x] = 0;
check--;
break;
}
}
if(source == b11)
{
if(select == ItemEvent.SELECTED)
{
num[x] = 11;
check++;
break;
}
else
{
num[x] = 0;
check--;
break;
}
}
if(source == b12)
{
if(select == ItemEvent.SELECTED)
{
num[x] = 12;
check++;
break;
}
else
{
num[x] = 0;
check--;
break;
}
}
if(source == b13)
{
if(select == ItemEvent.SELECTED)
{
num[x] = 13;
check++;
break;
}
else
{
num[x] = 0;
check--;
break;
}
}
if(source == b14)
{
if(select == ItemEvent.SELECTED)
{
num[x] = 14;
check++;
break;
}
else
{
num[x] = 0;
check--;
break;
}
}
if(source == b15)
{
if(select == ItemEvent.SELECTED)
{
num[x] =15;
check++;
break;
}
else
{
num[x] = 0;
check--;
break;
}
}
if(source == b16)
{
if(select == ItemEvent.SELECTED)
{
num[x] = 16;
check++;
break;
}
else
{
num[x] = 0;
check--;
break;
}
}
if(source == b17)
{
if(select == ItemEvent.SELECTED)
{
num[x] = 17;
check++;
break;
}
else
{
num[x] = 0;
check--;
break;
}
}
if(source == b18)
{
if(select == ItemEvent.SELECTED)
{
num[x] = 18;
check++;
break;
}
else
{
num[x] = 0;
check--;
break;
}
}
if(source == b19)
{
if(select == ItemEvent.SELECTED)
{
num[x] = 19;
check++;
break;
}
else
{
num[x] = 0;
check--;
break;
}
}
if(source == b20)
{
if(select == ItemEvent.SELECTED)
{
num[x] = 20;
check++;
break;
}
else
{
num[x] = 0;
check--;
break;
}
}
if(source == b21)
{
if(select == ItemEvent.SELECTED)
{
num[x] = 21;
check++;
break;
}
else
{
num[x] = 0;
check--;
break;
}
}
if(source == b22)
{
if(select == ItemEvent.SELECTED)
{
num[x] = 22;
check++;
break;
}
else
{
num[x] = 0;
check--;
break;
}
}
if(source == b23)
{
if(select == ItemEvent.SELECTED)
{
num[x] = 23;
check++;
break;
}
else
{
num[x] = 0;
check--;
break;
}
}
if(source == b24)
{
if(select == ItemEvent.SELECTED)
{
num[x] = 24;
check++;
break;
}
else
{
num[x] = 0;
check--;
break;
}
}
if(source == b25)
{
if(select == ItemEvent.SELECTED)
{
num[x] = 25;
check++;
break;
}
else
{
num[x] = 0;
check--;
break;
}
}
if(source == b26)
{
if(select == ItemEvent.SELECTED)
{
num[x] = 26;
check++;
break;
}
else
{
num[x] = 0;
check--;
break;
}
}
if(source == b27)
{
if(select == ItemEvent.SELECTED)
{
num[x] = 27;
check++;
break;
}
else
{
num[x] = 0;
check--;
break;
}
}
if(source == b28)
{
if(select == ItemEvent.SELECTED)
{
num[x] = 28;
check++;
break;
}
else
{
num[x] = 0;
check--;
break;
}
}
if(source == b29)
{
if(select == ItemEvent.SELECTED)
{
num[x] = 29;
check++;
break;
}
else
{
num[x] = 0;
check--;
break;
}
}
if(source == b30)
{
if(select == ItemEvent.SELECTED)
{
num[x] = 30;
check++;
break;
}
else
{
num[x] = 0;
check--;
break;
}
}
}
}
public void actionPerformed(ActionEvent a)
{
Object source = a.getSource();
pickedNumbers.setText(num[0] + " " + num[1] + " " + num[2] + " " + num[3] + " " + num[4] + " " + num[5]);
result.setText(resultNum1 + " " + resultNum2 + " " + resultNum3 + " " + resultNum4 + " " + resultNum5 + " " + resultNum6);
}
public static void main(String[]args)
{
new lottoDraw();
}
}