Note that there are some explanatory texts on larger screens.

plurals
  1. POTrouble with CheckBox matrix, loops won't work
    primarykey
    data
    text
    <p>I am writing a program which will have multiple windows that will pass a value between them. Currently I am testing one part of my program that is made out of 1-99 checkboxes. But when I want to check their states by clicking on a button it just doesn't work. Here's where the problem is:</p> <pre><code>public void actionPerformed(ActionEvent event) { if(event.getSource() == okay) { for(int i=0;i&lt;box.length; i++){ for(int j=0;j&lt;box.length; j++){ if((i==0)&amp;&amp;(j==0)) continue; if(box[i][j].getState()) asdf.matra[i][j]=true; System.out.println(box[i][j].getLabel() + " is " + asdf.matra[i][j]); } } } } </code></pre> <p>here's the main class:</p> <pre><code> public class asdf { public static boolean matra[][] = new boolean[10][10]; public static void main(String arg[]) { for(int ii=0;ii&lt;matra.length; ii++){ for(int jj=0;jj&lt;matra.length; jj++){ matra[ii][jj]=false; } } new JFrameDemo(); } } </code></pre> <p>and the other class:</p> <pre><code>import java.awt.*; import java.awt.event.WindowEvent; import java.awt.event.ActionListener; import java.awt.event.ActionEvent; import java.awt.event.ItemListener; import java.awt.event.ItemEvent; public class JFrameDemo extends Frame implements ActionListener, ItemListener { Checkbox box[][] = new Checkbox[10][10]; Button okay; JFrameDemo() { enableEvents(AWTEvent.WINDOW_EVENT_MASK); add(makePanel()); pack(); show(); } private Panel makePanel() { GridBagConstraints con = new GridBagConstraints(); Panel panel = new Panel(); GridBagLayout gridbag = new GridBagLayout(); panel.setLayout(gridbag); for(int i=0;i&lt;box.length; i++){ for(int j=0;j&lt;box.length; j++){ if((i==0)&amp;&amp;(j==0)) continue; box[i][j] = new Checkbox(i+j*10+""); con.gridx = i; con.gridy = j; panel.add(box[i][j],con); } } okay = new Button("Unesi"); con.gridx = 10; con.gridy = 10; panel.add(okay,con); return(panel); } public void actionPerformed(ActionEvent event) { if(event.getSource() == okay) { for(int i=0;i&lt;box.length; i++){ for(int j=0;j&lt;box.length; j++){ if((i==0)&amp;&amp;(j==0)) continue; if(box[i][j].getState()) asdf.matra[i][j]=true; System.out.println(box[i][j].getLabel() + " is " + asdf.matra[i][j]); } } } } public void itemStateChanged(ItemEvent event) { } public void processWindowEvent(WindowEvent event) { if(event.getID() == WindowEvent.WINDOW_CLOSING) System.exit(0); } } </code></pre> <p>The program is running without any errors, but the console isn't giving any results. It is supposed to pass value to the global variable also. I think there's an issues with nested fors. </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload