Scroll2 (other files are same as before)

Main.java  [download]

/*
 * Add Java/Swing boilerplate
 */

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

import java.awt.EventQueue;
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) { //*2 New startup procedure: equivalent code
        /* Equivalent to code below
	class MyRun implements Runnable { //*2
	    public void run() { //*2
		new Main (); //*2
            } //*2
        } //*2
	//*2
	MyRun myRun = new MyRun (); //*2
	//*2
	java.awt.EventQueue.invokeLater (myRun); { //*2
	*/

	java.awt.EventQueue.invokeLater (new Runnable() { //*3 New startup procedure: actual code
	    public void run() { //*3
		new Main (); //*3
            } //*3
        }); //*3
    }

    public Main () {
	// Window setup
	setDefaultCloseOperation (EXIT_ON_CLOSE); //*1 Quit process when close window
	setSize (300, 300);
	Container content = getContentPane();
	content.setLayout (new FlowLayout());

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

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

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

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