30-08-2011, 12:38 PM
Code:
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
/*
<applet code=SBDemo width=300 height=300>
</applet>
*/
public class SBDemo extends Applet
implements AdjustmentListener,MouseMotionListener
{
String msg = " ";
Scrollbar verSB,horSB;
public void init()
{
int width = Integer.parseInt(getParameter("width"));
int height = Integer.parseInt(getParameter("height"));
verSB = new Scrollbar(Scrollbar.VERTICAL,0,1,0,height);
horSB = new Scrollbar(Scrollbar.HORIZONTAL,0,1,0,width);
add(verSB);
add(horSB);
verSB.addAdjustmentListener(this);
horSB.addAdjustmentListener(this);
addMouseMotionListener(this);
}
public void adjustmentValueChanged(AdjustmentEvent ae)
{
repaint();
}
public void mouseMoved(MouseEvent me)
{ }
public void mouseDragged(MouseEvent me)
{ }
public void paint(Graphics g)
{
msg = "Vertical : " + verSB.getValue();
msg += ",Horizontal: " + horSB.getValue();
g.drawString(msg,6,160);
g.drawString("*",horSB.getValue(),verSB.getValue());
}
}