Scroll1 (other files are same as before)

Main.java  [download]

/*
 * Like simple button, but showing Silder
 */

import java.awt.Frame;
import java.awt.Container;
import java.awt.FlowLayout;

import java.awt.event.ActionListener;
import java.awt.event.AdjustmentListener;

import javax.swing.JFrame;

public class Main extends JFrame {
    public static void main (String [] args) {
	new Main ();
    }
    
    public Main () {
	// Window setup
	setSize (300, 300);
	Container content = getContentPane();
	content.setLayout (new FlowLayout());

	// Put a scrollbar in it, don't bother remembering
	content.add (new MyScrollBar (1)); //*1 Just create it and add() it in

	// Put another scrollbar
	content.add (new MyScrollBar (2)); //*1

	// And a button, for good measure
	content.add (new MyButton ("Push me")); //*1

	// Show the window
	setVisible (true);
    }
}

MyScrollBar.java  [download]

import java.awt.event.AdjustmentListener;
import java.awt.event.AdjustmentEvent;

import javax.swing.JScrollBar;

public class MyScrollBar extends JScrollBar implements AdjustmentListener { //*1 Uses a different listener
    // My private ID number, so I can tell my scrollbar's apart
    private int id; //*3 Remember ID number

    public MyScrollBar (int id) {
	// Customize properties of our ScrollBar
	// Named static constant
	setOrientation (HORIZONTAL); //*5 Set some JScrollBar properties
	setMinimum (0); //*5
	setMaximum (100); //*5
	// Initial value
	setValue (25); //*5

	this.id = id; //*3
	addAdjustmentListener (this); //*1
    }

    public void adjustmentValueChanged (AdjustmentEvent event) { //*2 Uses different callback event = value changed
	    System.out.println ("Scrollbar " + id + ": new value = " + getValue()); //*4 Uses JScrollBar.getValue()
    }
}