M2G Posted December 30, 2010 Report Posted December 30, 2010 (edited) Am un proiect in java si am inceput sa imi prind urechile.Deci: Se da formul din imagine Vreau sa fac astfel incat dimensiunea acelui grid de butoane sa se modifice in functie de ce aleg pe acele radiobuttons.Acum gridul este generat de o variabila pe care am initializat-o cu 3. (ca sa vedeti despre ce e vorba) public Xsi0View(SingleFrameApplication app) { super(app); [COLOR="Red"]grid=3[/COLOR]; [COLOR="Red"]int dimensiune = (grid*grid)[/COLOR]; initComponents(); for(int i=1; i<=dimensiune; i++){ buttons[i] = new JButton(); tabla.add(buttons[i]); buttons[i].addActionListener(this); } }Aici e initComponents cu elementele de GUI generat de Net Beans:private void initComponents() { mainPanel = new javax.swing.JPanel(); tabla = new javax.swing.JPanel(); dimensiuni = new javax.swing.JPanel(); dimensiune3 = new javax.swing.JRadioButton(); dimensiune5 = new javax.swing.JRadioButton(); dimensiune7 = new javax.swing.JRadioButton(); dimensiune9 = new javax.swing.JRadioButton(); grupbutoane = new javax.swing.ButtonGroup(); mainPanel.setName("mainPanel"); // NOI18N mainPanel.setPreferredSize(new java.awt.Dimension(988, 873)); tabla.setAutoscrolls(true); tabla.setName("tabla"); // NOI18N tabla.setLayout(new java.awt.GridLayout([COLOR="Red"]grid, grid[/COLOR] )); dimensiuni.setName("dimensiuni"); // NOI18N dimensiuni.setLayout(new java.awt.GridLayout(3, 3)); grupbutoane.add(dimensiune3); org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(xsi0.Xsi0App.class).getContext().getResourceMap(Xsi0View.class); dimensiune3.setText(resourceMap.getString("dimensiune3.text")); // NOI18N dimensiune3.setName("dimensiune3"); // NOI18N dimensiuni.add(dimensiune3); grupbutoane.add(dimensiune5); dimensiune5.setText(resourceMap.getString("dimensiune5.text")); // NOI18N dimensiune5.setName("dimensiune5"); // NOI18N dimensiuni.add(dimensiune5); grupbutoane.add(dimensiune7); dimensiune7.setText(resourceMap.getString("dimensiune7.text")); // NOI18N dimensiune7.setName("dimensiune7"); // NOI18N dimensiuni.add(dimensiune7); grupbutoane.add(dimensiune9); dimensiune9.setText(resourceMap.getString("dimensiune9.text")); // NOI18N dimensiune9.setName("dimensiune9"); // NOI18N dimensiuni.add(dimensiune9); javax.swing.GroupLayout mainPanelLayout = new javax.swing.GroupLayout(mainPanel); mainPanel.setLayout(mainPanelLayout); mainPanelLayout.setHorizontalGroup( mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(mainPanelLayout.createSequentialGroup() .addGap(66, 66, 66) .addComponent(dimensiuni, javax.swing.GroupLayout.PREFERRED_SIZE, 234, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 31, Short.MAX_VALUE) .addComponent(tabla, javax.swing.GroupLayout.PREFERRED_SIZE, 708, javax.swing.GroupLayout.PREFERRED_SIZE) .addContainerGap()) ); mainPanelLayout.setVerticalGroup( mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(mainPanelLayout.createSequentialGroup() .addContainerGap(114, Short.MAX_VALUE) .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, mainPanelLayout.createSequentialGroup() .addComponent(dimensiuni, javax.swing.GroupLayout.PREFERRED_SIZE, 242, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(32, 32, 32)) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, mainPanelLayout.createSequentialGroup() .addComponent(tabla, javax.swing.GroupLayout.PREFERRED_SIZE, 471, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(19, 19, 19)))) ); setComponent(mainPanel); }// </editor-fold> // <editor-fold defaultstate="collapsed" desc="comment"> // Variables declaration - do not modify private javax.swing.JRadioButton dimensiune3; private javax.swing.JRadioButton dimensiune5; private javax.swing.JRadioButton dimensiune7; private javax.swing.JRadioButton dimensiune9; private javax.swing.JPanel dimensiuni; private javax.swing.ButtonGroup grupbutoane; private javax.swing.JPanel mainPanel; private javax.swing.JPanel tabla; // End of variables declarationIntrebarea mea este cum fac ca atunci cand aleg unul din acele radiobuttons sa imi modifice variabila "grid" astfel incat sa am o tabla de butoane de 3x3, 5x5, 7x7 respectiv 9x9?Sau daca aveti alte idei fara acea variabila "grid"...Am nevoie de acest grid de butoane pentru a putea face un joc de genul x-0 cu dimeniuni variabile introduse de utilizator prin acele radiobuttons. Edited December 30, 2010 by M2G Quote