Here is my assignment: In Chapter 5, you created a lottery game application. Create a similar game using check boxes. For this game, generate six random numbers, each between 0 and 30 inclusive. Allow the user to choose six check boxes to play the game. (Do not allow the user to choose more than six boxes.) After the player has chosen six numbers, display the randomly selected numbers, the player ’ s numbers, and the amount of money the user has won, as follows: Matching Numbers Three matches Four matches Five matches Six matches Zero, one, or two matches Award ($) 100 10,000 50,000 1,000,000 0
Additional requirements are as follows:
• Add a menu bar to the program with a File menu.
• In the File menu, add a submenu (JMenuItem) called About.
• When the user clicks on the About menu item, display a
JOptionPane message dialog that contains your name, your
course, the section number, and MEID.
The primary issue I am having is with the limiting of checkboxes, I cannot seem to find examples of this in the text or anywhere online (except in javascript and html, which obviously do not help me here.) I have posted my code below. Please note that I am only looking for answers to the limit on check boxes at the moment the rest of the code I can complete myself.
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
public class JLottery2 extends JFrame implements ActionListener
{
//instantiate constants
final int HIGHEST_VAL = 30;
final int LOWEST_VAL = 1;
final int BOXES_CHECKED = 6;
final int WIDE = 400;
final int TALL = 400;
//set random number generator
int numR = ((int) (Math.random() * 100) % HIGHEST_VAL + LOWEST_VAL);
int numR2 = ((int) (Math.random() * 100) % HIGHEST_VAL + LOWEST_VAL);
int numR3 = ((int) (Math.random() * 100) % HIGHEST_VAL + LOWEST_VAL);
int numR4 = ((int) (Math.random() * 100) % HIGHEST_VAL + LOWEST_VAL);
int numR5 = ((int) (Math.random() * 100) % HIGHEST_VAL + LOWEST_VAL);
int numR6 = ((int) (Math.random() * 100) % HIGHEST_VAL + LOWEST_VAL);
@SuppressWarnings("LeakingThisInConstructor")
public JLottery2()
{
//set title and size of the frame
setTitle("Final Project");
setSize(750, 750);
// Creates a menubar for a JFrame
JMenuBar menuBar = new JMenuBar();
// Add the menubar to the frame
setJMenuBar(menuBar);
// Define and add two drop down menu to the menubar
JMenu fileMenu = new JMenu("File");
menuBar.add(fileMenu);
// Create and add simple menu item to one of the drop down menu
JMenuItem aboutAction = new JMenuItem("About");
//add about to the file menu
fileMenu.add(aboutAction);
//set the layout for the checkboxes
JPanel checkBoxPane = new JPanel();
checkBoxPane.setLayout(new GridLayout(6, 5));
//instantiate new checkboxes
JCheckBox box1 = new JCheckBox("1");
JCheckBox box2 = new JCheckBox("2");
JCheckBox box3 = new JCheckBox("3");
JCheckBox box4 = new JCheckBox("4");
JCheckBox box5 = new JCheckBox("5");
JCheckBox box6 = new JCheckBox("6");
JCheckBox box7 = new JCheckBox("7");
JCheckBox box8 = new JCheckBox("8");
JCheckBox box9 = new JCheckBox("9");
JCheckBox box10 = new JCheckBox("10");
JCheckBox box11 = new JCheckBox("11");
JCheckBox box12 = new JCheckBox("12");
JCheckBox box13 = new JCheckBox("13");
JCheckBox box14 = new JCheckBox("14");
JCheckBox box15 = new JCheckBox("15");
JCheckBox box16 = new JCheckBox("16");
JCheckBox box17 = new JCheckBox("17");
JCheckBox box18 = new JCheckBox("18");
JCheckBox box19 = new JCheckBox("19");
JCheckBox box20 = new JCheckBox("20");
JCheckBox box21 = new JCheckBox("21");
JCheckBox box22 = new JCheckBox("22");
JCheckBox box23 = new JCheckBox("23");
JCheckBox box24 = new JCheckBox("24");
JCheckBox box25 = new JCheckBox("25");
JCheckBox box26 = new JCheckBox("26");
JCheckBox box27 = new JCheckBox("27");
JCheckBox box28 = new JCheckBox("28");
JCheckBox box29 = new JCheckBox("29");
JCheckBox box30 = new JCheckBox("30");
//add checkbox panel to the frame
add(checkBoxPane);
//add check boxes to the frame
checkBoxPane.add(box1);
checkBoxPane.add(box2);
checkBoxPane.add(box3);
checkBoxPane.add(box4);
checkBoxPane.add(box5);
checkBoxPane.add(box6);
checkBoxPane.add(box7);
checkBoxPane.add(box8);
checkBoxPane.add(box9);
checkBoxPane.add(box10);
checkBoxPane.add(box11);
checkBoxPane.add(box12);
checkBoxPane.add(box13);
checkBoxPane.add(box14);
checkBoxPane.add(box15);
checkBoxPane.add(box16);
checkBoxPane.add(box17);
checkBoxPane.add(box18);
checkBoxPane.add(box19);
checkBoxPane.add(box20);
checkBoxPane.add(box21);
checkBoxPane.add(box22);
checkBoxPane.add(box23);
checkBoxPane.add(box24);
checkBoxPane.add(box25);
checkBoxPane.add(box26);
checkBoxPane.add(box27);
checkBoxPane.add(box28);
checkBoxPane.add(box29);
checkBoxPane.add(box30);
//event handling
aboutAction.addActionListener(this);
}
@Override
public void actionPerformed(ActionEvent a)
{
//message to be displayed when About selection is made
JOptionPane.showMessageDialog(null, "Student Information Here");
}
//main method to execute
public static void main(String args[])
{
//instantiate object for execution
JLottery2 displayIt = new JLottery2();
displayIt.setVisible(true);
}
}