scroll_demo



->The symbol '*' moves according to the co-ordinates set by adjusting scrollbars.



import java.applet.*;
import java.awt.*;
import java.awt.event.*;
/*<applet code="scrolldemo" width=500 height=500>
  </applet>*/
public class scrolldemo extends Applet implements AdjustmentListener,MouseMotionListener
{
Scrollbar VB,HB;
String msg=" ";
public void init()
{
int wh=Integer.parseInt(getParameter("width"));
int ht=Integer.parseInt(getParameter("height"));
VB=new Scrollbar(Scrollbar.VERTICAL,0,1,0,wh);
HB=new Scrollbar(Scrollbar.HORIZONTAL,0,1,0,ht);
add(VB);
add(HB);
VB.addAdjustmentListener(this);
HB.addAdjustmentListener(this);
addMouseMotionListener(this);
}
public void adjustmentValueChanged(AdjustmentEvent ae)
{
repaint();
}
public void mouseMoved(MouseEvent me)
{
}
public void mouseDragged(MouseEvent me)
{
int x=me.getX();
int y=me.getY();
VB.setValue(y);
HB.setValue(x);
repaint();
}
public void paint(Graphics g)
{
msg="Vertical:" + VB.getValue() + "," + "Horizontal:" + HB.getValue();
g.drawString(msg,40,50);
g.drawString("*",HB.getValue(),VB.getValue());
}
}

No comments:

Post a Comment