How can I create a 20-number Banners look on the Jframe

5

It is a game where your bet will be competing for Sena, Quina and Quadra, so each bet can only have 6 numbers, I need the user to select 6 numbers out of these 20 and then I pick up the 6 selected ones and place his bet . But I just need this Betting Card .

So how can I create a Betting Card of 20 numbers where you will select only 6 of them by clicking on it, then picking up the numbers that have been selected.
The comparison part and create numbers randomly is ready and working, I am using 6 JComboBox from 1 to 20 for the user to choose the 6 numbers, but would be more practical if he clicked on the numbers scattered on the screen, I also wanted a ball behind each number to give an idea of Bingo. Thank you for your attention!

    
asked by anonymous 03.12.2014 / 16:11

1 answer

3

Check the code, I think this is more practical than selecting the numbers for a combobox , it is necessary to implement the rule to only let you select 5 numbers, but this I think you can do now.

Code:

public class Matrizz extends javax.swing.JFrame {
private List<JToggleButton> listTogglebu = new ArrayList<JToggleButton>(20);
/**
 * Creates new form Matrizz
 */
public Matrizz() {
    initComponents();
    JPanel jPanel1 = new JPanel();
    JPanel jPanel2 = new JPanel();
    this.setLayout(new GridLayout(2,0));
    jPanel1.setBorder(new EmptyBorder(5, 5, 5, 5));
    this.setSize(500,300);
    this.add(jPanel1);
    this.add(jPanel2);
    jPanel1.setLayout(new GridLayout(2, 10));



    for (int y = 0; y < 20; y++) {
        listTogglebu.add(new JToggleButton("" + (y + 1)));
        jPanel1.add(listTogglebu.get(y));
    }
    JButton ver = new JButton("Selecionados");

    jPanel2.add(ver);
     ver.addActionListener( new ActionListener() {
                 public void actionPerformed(ActionEvent e) {
                      printSelecionado();
                 }


        });


}
  private void printSelecionado() {
            for (JToggleButton jToggleButton : listTogglebu) {
                if(jToggleButton.isSelected())System.out.println(" numero:"+jToggleButton.getText());

      }
        }

result:

output:

run:  
numero:3
numero:4
numero:6
numero:12 
numero:15
numero:17
    
03.12.2014 / 17:07