Hi there,
I think
you should put the listener on the scrollbar i.e AdjustmentListener and use this method getValue() of AdjustmentEvent class.
I am giving you the example on
applet, hope you will find it useful.....
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
/** <applet code = "ScrollDemo.class" width = 300 height = 300>
</applet> */
public class ScrollDemo extends Applet
{
Scrollbar hsb;
Scrollbar vsb;
int v,h;
public void init(){
setLayout(new BorderLayout());
hsb = new Scrollbar(Scrollbar.HORIZONTAL,1,10,0,size().width);
vsb = new Scrollbar(Scrollbar.VERTICAL,1,10,0,size().height);
add("North",hsb);
add("East",vsb);
hsb.addAdjustmentListener(new AdjustmentListener(){
public void adjustmentValueChanged(AdjustmentEvent ae){
h=hsb.getValue();
v=vsb.getValue();
showStatus(h+""+","+v);
repaint();
}
});
vsb.addAdjustmentListener(new AdjustmentListener(){
public void adjustmentValueChanged(AdjustmentEvent ae){
h=hsb.getValue();
v=vsb.getValue();
showStatus(h+""+","+v);
repaint();
}
});
}
public void paint(Graphics g){
g.drawOval(50,50,h,v);
}
}
Bye...