The Java Program: ScrollbarDemo.java

  1 // ScrollbarDemo.java -- illustrate component "Scrollbar"; adapted from Naughton
  2 
  3 /*
  4    Example of how to use this applet in an HTML file:
  5    <applet code="ScrollbarDemo" width=200 height=100></applet>
  6 */
  7 
  8 import java.applet.Applet;
  9 import java.awt.Dimension;
 10 import java.awt.Scrollbar;
 11 
 12 public class ScrollbarDemo extends Applet {
 13 
 14    public void init() {
 15       setLayout(null);
 16 
 17       Dimension d = this.getSize();
 18       int width  = d.width;
 19       int height = d.height;
 20 
 21       Scrollbar hs = new Scrollbar (
 22          Scrollbar.HORIZONTAL, 50, width / 10, 0, 100);
 23       Scrollbar vs = new Scrollbar (
 24          Scrollbar.VERTICAL, 50, height / 2, 0, 100);
 25 
 26       add(hs);
 27       add(vs);
 28 
 29       int thickness = 16;
 30       hs.setBounds (0, height-thickness, width-thickness, thickness);
 31       vs.setBounds (width-thickness, 0, thickness, height-thickness);
 32    }
 33 }