I'm trying to create a Bingo game using NetBeans IDE 6.9.1 (I'm a noob at coding). Right now I'm stuck at trying to create the bingo card. For the 5x5 card's boxes I used jButtons. I can't randomize the "B" bingo balls down the "B" collumn. I have a code that "works" for randomizing which "B" ball goes in which "B" jButton, but my method will not work for the jLabel I'm using to output the randomly drawed bingo ball. Here's my "random B-ball code:"
String[] Bball1 = {"B5", "B6", "B11"};
String Brandom1 = (Bball1[new Random().nextInt(Bball1.length)]);
String[] Bball2 = {"B1", "B8", "B15"};
String Brandom2 = (Bball2[new Random().nextInt(Bball2.length)]);
String[] Bball3 = {"B3", "B10", "B13"};
String Brandom3 = (Bball3[new Random().nextInt(Bball3.length)]);
String[] Bball4 = {"B2", "B9", "B14"};
String Brandom4 = (Bball4[new Random().nextInt(Bball4.length)]);
String[] Bball5 = {"B4", "B7", "B12"};
String Brandom5 = (Bball5[new Random().nextInt(Bball5.length)]);
Here is the code for when the user clicks the submit button when they pick a bingo pattern and the card would be generated (incomplete):
btnSubmit.setEnabled(false);
cboPattern.setEnabled(false);
btn1B.setText(Brandom1);
btn2B.setText(Brandom2);
btn3B.setText(Brandom3);
btn4B.setText(Brandom4);
btn5B.setText(Brandom5);
Yes, this is repetitive, and not overly random, but I did some research on Arrays, as I have not learned them in my Computer Science class, and got this:
public static void main(String[] Bballs) {
String[] Bball;
Bball = new String[2];
Bball[0] = "B1";
Bball[1] = "B2";
Bball[2] = "B3";
int num = (int) (Math.random() * 2);
System.out.println(Bball[num]);
}
This is just a test code, and as you can see I could still get B1 more than one time which isn't what I want for the bingo card and the randomly picked bingo balls (which I haven't started yet). Plus, whenever I run my program it doesn't print out the last line. I need this done by the end of Wednesday :/ (It's a late ISU project, and no I did not start it late). Thanks for your time.
Aucun commentaire:
Enregistrer un commentaire