import java.awt.*;
import java.awt.event.*;
import javax.swing.event.*;
import javax.swing.*;
import javax.swing.border.*;
import java.applet.*;
import java.net.*;

/** Bare bones program to demonstrate <code>JScrollBar</code>.<p>
*
* Screen snap...<br>
* <center><img src="DemoScrollBarBB-1.gif"></center><p>
*
* <b>Source code notes:</b><br>
*
* It's unlikely that a <code>JScrollBar</code>
* component would be instantiated directly.
* Rather, <code>JSrollBar</code> components are
* instantiated indirectly as part of another component,
* such as <code>JScrollPane</code>.<p>
*
* @see <a href="DemoScrollBarBB.java">source code</a>
* @author Scott MacKenzie, 2002
*/
public class DemoScrollBarBB
{
   public static void main(String[] args)
   {
      // commented out (Java L&F appears better!)
      //{
      //   UIManager.setLookAndFeel(
      //      UIManager.getSystemLookAndFeelClassName());
      //} catch (Exception e) {}

      DemoScrollBarBBFrame frame = new DemoScrollBarBBFrame();
      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      frame.setTitle("DemoScrollBarBB");
      frame.pack(); 
      frame.show();      
   }
}

class DemoScrollBarBBFrame extends JFrame implements AdjustmentListener
{
   private JScrollBar scrollbar;
   private JTextField scrollbarValue;

   // constructor

   public DemoScrollBarBBFrame()
   {
      // ----------------------------------
      // construct and configure components
      // ----------------------------------

      // create and configure the scrollbar

      scrollbar = new JScrollBar(SwingConstants.HORIZONTAL);
      scrollbar.setValue(50);
      scrollbar.setVisibleAmount(10);
      scrollbar.setMinimum(0);
      scrollbar.setMaximum(500);

      // create value field to display scrollbar's current setting

      final int SIZE = 4;
      final Color LIGHT_GREY = new Color(225, 225, 225);
      scrollbarValue = new JTextField(SIZE);
      scrollbarValue.setEditable(false);
      scrollbarValue.setBackground(LIGHT_GREY);
      scrollbarValue.setHorizontalAlignment(SwingConstants.CENTER);

      // set initial value to scrollbar's initial setting

      scrollbarValue.setText("" + scrollbar.getValue());

      // -------------
      // add listeners
      // -------------

      scrollbar.addAdjustmentListener(this);

      // -----------------
      // layout components
      // -----------------

      // add components to panel

      JPanel panel = new JPanel();
      panel.add(new JLabel("Scrollbar"));
      panel.add(scrollbar);
      panel.add(scrollbarValue);
      panel.setBorder(new TitledBorder(new EtchedBorder(),
         "Scrollbar demo (bare bones)"));

      // put in another panel -- just to add an empty border
      JPanel contentPane = new JPanel();
      contentPane.add(panel);
      contentPane.setBorder(BorderFactory.createEmptyBorder(30, 30, 30, 30));

      // make panel this JFrame's content pane

      this.setContentPane(contentPane);
   }

   // -----------------------------------
   // implement AdjustmentListener method
   // -----------------------------------

   public void adjustmentValueChanged(AdjustmentEvent ae)
   {
      JScrollBar source = (JScrollBar)ae.getSource();

      // get the scrollbar's current value
      int newValue = source.getValue();

      // print it!
      System.out.print(newValue + " ");

      // update the text field
      scrollbarValue.setText("" + newValue);
   }
}

