title: Color changing using Scrollbar in java
body: <p>i want to change the background color of frame as per the value selected in 3 scrollbar?
  But it is not happening here is my code.</p>
  
  <pre><code>import java.awt.*;
  import java.awt.event.*;
  import javax.swing.*;
  
  class changeColor extends JFrame implements AdjustmentListener
  {
      JScrollBar red;
      JScrollBar green;
      JScrollBar blue;
  
  
      changeColor()
      {
          super("SCROLLBAR DEMO");
          setLayout(new FlowLayout());
          setVisible(true);
          setSize(300,300);
          setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          red=new JScrollBar(JScrollBar.HORIZONTAL);
          green=new JScrollBar(JScrollBar.HORIZONTAL);
          blue=new JScrollBar(JScrollBar.HORIZONTAL);
          add(red);
          add(green);
          add(blue);
          red.addAdjustmentListener(this);
          green.addAdjustmentListener(this);
          blue.addAdjustmentListener(this);   
      }
  
      public void adjustmentValueChanged(AdjustmentEvent ae)
      {
          int cr=0;
          int cg=0;
          int cb=0;
          if(ae.getSource()==red)
              cr=ae.getValue();
          else if(ae.getSource()==green)
              cg=ae.getValue();
          else if(ae.getSource()==blue)
              cb=ae.getValue();
  
          setBackground(new Color(cr,cg,cb)); 
      }
  
  
      public static void main(String args[])
      {
          changeColor obj=new changeColor();  
      }
  }
  </code></pre>
  
  <p>The problem is that the background color is not changing.
  I want to know what is the problem and how can i fix it?</p>