[963] in java-interest

home help back first fref pref prev next nref lref last post

Re: Scrolling & Stuff

daemon@ATHENA.MIT.EDU (Lein Ton)
Tue Aug 15 22:51:36 1995

Date: Tue, 15 Aug 1995 11:26:34 -0400
From: ton@cc.gatech.edu (Lein Ton)
To: rharriso@elmer.tcinc.com, java-interest@java.sun.com

Hi Ray,
I think by now you figured out how the scrolling works, but in case
you didn't, you might wanna look at the program beneath. It's
not a very nice way of scrolling, but it works. If you plan on 
scrolling a lot of objects this way you might consider putting 
everything in a window and move the window instead of the 
individual things.
You also might wanna look at 
http://java.sun.com/archives/java-interest/0761.html
in case you want to delete things from a window, I figured that the
easiest way of clearing the childList is to create a new one and
copy the items that are not deleted to the new one, and assign it
to ScrollWindow.childList.
If you found an easier way of scrolling, please let me know!

Lein

------------little program that demonstrates "scrolling"-------
import awt.*;
import java.util.*;
class ScrollWindow extends Window {
//variables; static because they're defined in the object that contains "main"
  public static  Label l;
  public static Button b;
  public static Scrollbar sb;
//oldY contains the previous value of the scrollbar
  public static int oldY=0;
//constructor
  public ScrollWindow(Frame f, String name) {
    super (f,name,Color.green,200,200);
  }
//implementation of dragAbsolute; called by the scrollbar when it is dragged
  public void dragAbsolute(int value) {
	for (Enumeration e = children.elements(); e.hasMoreElements();)
	{
	   int dy = oldY-sb.value();
	   Component c = ((Component)(e.nextElement()));
	   c.move(0,c.y-dy);
	}
        oldY=sb.value();

  }
public static void main (String args[]) {
// create a ScrollWindow
  WServer ws = new WServer();
  ws.start();
  Frame fr = new Frame(ws,false,null,200,200,Color.lightGray);
  fr.name = "myframe";
  ScrollWindow sw = new ScrollWindow(fr,"swname");
// attach a ScrollBar
  sb = new Scrollbar(sw,"sbName",Scrollbar.VERTICAL,true);
  sb.setScrollTarget(sw);
// put something in the window to demonstrate scrolling
  l = new Label("I can move","icml", sw);
  b = new Button("I can move 2","icmb",sw);
  b.move(50,50);
  fr.map();
}
}

-
Note to Sun employees: this is an EXTERNAL mailing list!
Info: send 'help' to java-interest-request@java.sun.com

home help back first fref pref prev next nref lref last post