import java.awt.*; public class ScrollableScribble extends Panel { Canvas canvas; Scrollbar hbar,vbar; java.util.Vector lines = new java.util.Vector(100,100); int last_x,last_y; int offset_x,offset_y; int canvas_width,canvas_height; // Create a canvas and two scrollbars and lay them out in the panel. // Use a BorderLayout to get the scrollbarsflush against the // right and bottom sides of the canvas. When the panel grows, // the convas and scrollbars will also grow appropriately. public ScrollableScribble() { // implicit super() call here creates the panel canvas = new Canvas(); hbar = new Scrollbar(Scrollbar.HORIZONTAL); vbar = new Scrollbar(Scrollbar.VERTICAL); this.setLayout(new BorderLayout(0,0)); this.add("Center",canvas); this.add("South",hbar); this.add("East",vbar); } // Draw the scribbles that weÕve saved in the Vector // the offset_x and offset_y variables specify which portion of // the larger (1000x1000) scribble is to be displayed in the // relatively small canvas. Moving the scrollbars changes these // variables, and thus scrolls the picture. Note that the Canvas // component automatically does clipping; we canÕt accidentally // draw outside of its borders. public void paint(Graphics g) { Line L; Graphics canvas_g = canvas.getGraphics(); for (int i=0; i