1  /*
  2   *  File:  ScrollbarDemo.java
  3   *
  4   *  Create a scrollbar (i.e., a slide control)
  5   *
  6   *  Copyright:  Northeast Parallel Architectures Center
  7   *  
  8   */
  9  
 10  import java.awt.Label;
 11  import java.awt.Scrollbar;
 12  import java.awt.Color;
 13  import java.awt.BorderLayout;
 14  import java.awt.Font;
 15  
 16  public class ScrollbarDemo extends java.applet.Applet {
 17    
 18    private Label labelLeft, labelRight;
 19    private Scrollbar scrollbar;
 20  
 21    public void init() {
 22      setBackground( Color.white );
 23      Color lightBlue = new Color( 0xB0, 0xE0, 0xE6 );
 24      
 25      int min = 0;    // minimum value of scrollbar
 26      labelLeft = new Label( String.valueOf( min ) );
 27      labelLeft.setAlignment( Label.LEFT );
 28      labelLeft.setFont( new Font( "Serif", Font.PLAIN, 12 ) );
 29      
 30      int max = 100;  // maximum value of scrollbar
 31      labelRight = new Label( String.valueOf( max ) );
 32      labelRight.setAlignment( Label.RIGHT );
 33      labelRight.setFont( new Font( "Serif", Font.PLAIN, 12 ) );
 34      
 35      int pos = 50;   // initial position of scrollbox    
 36      int orientation = Scrollbar.HORIZONTAL;
 37      int size = 5;   // relative size of the scrollbox
 38      scrollbar = new Scrollbar( orientation, pos, size, min, max );
 39      scrollbar.setBlockIncrement(10);
 40      scrollbar.setBackground( lightBlue );
 41      
 42      // Add components to the applet:
 43      setLayout( new BorderLayout() );
 44      add( labelLeft, BorderLayout.WEST ); 
 45      add( labelRight, BorderLayout.EAST ); 
 46      add( scrollbar, BorderLayout.SOUTH );
 47      
 48    }
 49  
 50  }