How to pass values from public class to another public class?
<p>I was trying to pass values from one class to another. The class subPanel1 reads global variables bu when I update those variables through AdjustmentListener it doesn't change the value. I'm trying to pass rc, gc, and bc variables from subPanel2 class to subPanel1 class, and it only accepts initial value of global variable , but when i move jscrollbar variable doesnt change.  Here is my classes </p>

<pre><code>  import java.awt.event.ItemListener;
  import java.awt.event.AdjustmentEvent;
  import java.awt.event.AdjustmentListener;

  public class subPanel2 extends JPanel
  { 
   JScrollBar redbar,greenbar,bluebar;
   JRadioButton decimal,octal,binary,hex;

   int rc, gc, bc;
   int count;

   public subPanel2 ()
   {    
    setPreferredSize (new Dimension(150,500));
    setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS));

    JLabel red=new JLabel("Red");
    JLabel blue=new JLabel("Blue");
    JLabel green=new JLabel("Green");
    JLabel numsys=new JLabel("Numeral Systems");

    numsys.setForeground(Color.gray);

    JLabel colormix=new JLabel("Color Mix");
    colormix.setForeground(Color.gray);

    decimal=new JRadioButton("Decimal",true);
    octal=new JRadioButton("Octal");
    binary=new JRadioButton("Binary");
    hex=new JRadioButton("Hex");

    ButtonGroup group = new ButtonGroup();
    group.add(decimal);
    group.add(octal);
    group.add(binary);
    group.add(hex);

    decimal.addItemListener(new itemListener());
    octal.addItemListener(new itemListener());
    binary.addItemListener(new itemListener());
    hex.addItemListener(new itemListener());

    redbar= new JScrollBar(Adjustable.HORIZONTAL, 0, 0, 0, 255);
    redbar.setBlockIncrement(1);
    redbar.addAdjustmentListener(new adjustmentListener());

    greenbar= new JScrollBar(Adjustable.HORIZONTAL, 0, 0, 0, 255);
    greenbar.setBlockIncrement(1);
    greenbar.addAdjustmentListener(new adjustmentListener());

    bluebar= new JScrollBar(Adjustable.HORIZONTAL, 0, 0, 0, 255);
    bluebar.setBlockIncrement(1);
    bluebar.addAdjustmentListener(new adjustmentListener());

    add(numsys);
    add (Box.createRigidArea (new Dimension (0, 10)));
    add(decimal);
    add(octal);
    add(binary);
    add(hex);
    add (Box.createRigidArea (new Dimension (0, 30)));
    add(colormix);
    add (Box.createRigidArea (new Dimension (0, 10)));
    add(red);
    add(redbar);
    add(green);
    add(greenbar);
    add(blue);
    add(bluebar);
    } 

    public class adjustmentListener implements AdjustmentListener
    {
     public void adjustmentValueChanged(AdjustmentEvent adjustmentEvent) 
    {
      rc=redbar.getValue();
      gc=greenbar.getValue();
      bc=bluebar.getValue();
    }
    }

     private class itemListener implements ItemListener
     {
      public void itemStateChanged(ItemEvent itemEvent)
     {
      if (octal.isSelected()) count=8;
      else if (decimal.isSelected()) count=0;
      else if (binary.isSelected()) count=2;
      else if (hex.isSelected()) count=16;
     }
    }
    }




import javax.swing.JPanel;
import java.awt.*;

public class subPanel1 extends JPanel {

subPanel2 np;
public subPanel1 ()
{
 setPreferredSize (new Dimension(450,500));
}
 public void paintComponent (Graphics page)
{    
 np=new subPanel2();
 super.paintComponent (page);
 int p=10;
 String str="",str1="", str2="";
 String by="",by1="",by2="";

 if (np.count==2)
 {
  by = Integer.toBinaryString(np.rc);
  by1= Integer.toBinaryString(np.gc);
  by2 = Integer.toBinaryString(np.bc);
  str=by; 
  str1=by1;
  str2=by2; 
  }
  else if (np.count==16)
  {
by = Integer.toHexString(np.rc);
by1= Integer.toHexString(np.gc);
by2 = Integer.toHexString(np.bc);
str=by; 
str1=by1;
    str2=by2; 
   } 
   else
   { 
str=Integer.toString(np.rc,np.count);
str1=Integer.toString(np.gc,np.count);
    str2=Integer.toString(np.bc,np.count);
   }
    page.setColor (new Color(np.redbar.getValue(),np.gc,np.bc));
    page.fillOval(100, 340, 250, 150);
page.setColor(Color.red);
page.fillRect(85,260-np.rc,60,p+np.rc);
page.drawString("RED",100,310);
    page.drawString(str,105,325);    

page.setColor(Color.green);
page.fillRect(200,260-np.gc,60,p+np.gc);
page.drawString("GREEN",210,310);
page.drawString(str1,215,325);   

page.setColor (Color.blue);
page.fillRect(305,260-np.bc,60,p+np.bc);
page.drawString("BLUE",320,310);
page.drawString(str2,325,325);   
    }
    }`
</code></pre>
