for (int i=0; i<256; i++) { grays[i] = new Color(i, i, i); }
setLayout(new GridLayout(0, 1));
// create the slider and attach us as a listener
scale = new JSlider(JSlider.HORIZONTAL, 0, 255, 128);
scale.addChangeListener(this);
// Set up our display for the chooser
add(new JLabel("Pick your shade of gray:", JLabel.CENTER));
JPanel jp = new JPanel();
jp.add(new JLabel("Black"));
jp.add(scale);
jp.add(new JLabel("White"));
add(jp);