title: How to make binary number "wrap around" to 0 in an array?
body: <p>I am writing a program that converts decimal to binary by way of JLabel arrays and JTextfield for user input. I have a Step button that adds one to both the decimal number in the textbox and the binary number displayed each time it's pressed. However, when the number gets to 256 it is supposed to "wrap around" to 00000000, dropping the 1 in front. I'm not sure how to do this in the Listener, especially with no access to the private JLabel array (hence why i can't just do an "if num equals 256 then array sets text to 0" statement.) All I have to work with is the decimal number in the text box and the decimal to binary method. I've tried: </p>
  
  <pre><code>int i = Integer.parseInt(box.getText());
  
  if(i == 256);
   {
     display.setValue(0); //setValue is method to convert dec. to binary
     box.setText("" + i); //box is the JTextfield that decimal # is entered in
    }
  </code></pre>
  
  <p>and </p>
  
  <pre><code> if(i == 256)
     {
      i = i - i; 
      display.setValue(i); 
      } 
  </code></pre>
  
  <p>but neither of them worked and I'm out of ideas. I'd appreciate some help. Sorry for the lengthy explanation and thanks in advance! </p>
  
  <pre><code>public class Display11 extends JPanel
     {
      private JLabel[] output;
      private int[] bits;
      public Display11()
      {
     public void setValue(int num)//METHOD TO CONVERT DECIMAL TO BINARY
    {
      for(int x = 0; x &lt; 8; x++) //reset display to 0
       {
        bits[x] = 0;
       }
      int index = 0; //increments in place of a for loop
      while(num &gt; 0) 
     {
      int temp = num%2; //gives lowest bit 
      bits[bits.length - 1 - index] = temp; //set temp to end of array
      index++; 
      num = num / 2; //updates num 
  
      if(num == 0) //0 case
      {
       for(int x = 0; x &lt; 8; x++)
        {
         output[x].setText("0");
        }
      }
  
     }
      for(int x = 0; x &lt; bits.length; x++)
      {
      output[x].setText("" + bits[x]); //output is the JLabel array
      }                                //bits is a temporary int array
  
      //display the binary number in the JLabel
  
     public class Panel11 extends JPanel
     {
      private JTextField box;
      private JLabel label;
      private Display11 display;
      private JButton button2;
      public Panel11()
      {
       private class Listener2 implements ActionListener //listener for the incrementing button
        {
        public void actionPerformed(ActionEvent e)
        {
  
         int i = Integer.parseInt(box.getText()); //increments decimal # 
         i++; 
         box.setText("" + i); 
         display.setValue(i); //converts incremented decimal # to binary
  
       }
  
    }
  </code></pre>