public class Scroller extends Frame { public Scroller() { super("Scroller Example"); ScrollPane scroller = new ScrollPane(ScrollPane.SCROLLBARS_AS_NEEDED); scroller.add(new DrawCanvas()); Adjustable vadjust = scroller.getVAdjustable(); Adjustable hadjust = scroller.getHAdjustable(); hadjust.setUnitIncrement(10); vadjust.setUnitIncrement(10); scroller.setSize(200, 200); //200,200 add("Center", scroller); pack(); } // No more handleEvent method needed to implement scrolling! public static void main(String args[]) { Scroller test = new Scroller(); test.show(); } } class DrawCanvas extends Component { public Dimension getPreferredSize() { return new Dimension(300, 300); } // (300, 300)! public void paint(Graphics g) { // Note: For most efficient repainting, we should check the // clip rectangle in the Graphics object to determine the // damaged region and only paint that; we don't do that here // for simplicity in this example // Rectangle r = getBounds(); g.setColor(Color.black); g.fillRect(0, 0, r.width, r.height); g.setColor(Color.yellow); g.drawLine(0, 0, r.width, r.height); g.setColor(Color.white); g.drawLine(0, r.height, r.width, 0); } }
November 12, 2009.
I am finally done!!! I finished thru hiking the AT today (2178 miles)
New Hampshire / Maine