Monday, 22 December 2014

AdjustmentListener in Java

//save as AdjustmentListenerDemo.java
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
public class AdjustmentListenerDemo extends Applet implements AdjustmentListener
{
    Scrollbar slider;
    int x = 0;

    public void init()
    {             
        setLayout(null);

        slider = new Scrollbar(Scrollbar.HORIZONTAL, 0, 10, 0, 300);

        slider.setBounds(10,100,150,25);

        add(slider);
        slider.addAdjustmentListener(this);
    }

    public void adjustmentValueChanged(AdjustmentEvent ae)
    {
        x = ae.getValue();
        repaint();
    }

    public void paint(Graphics g)
    {
        g.drawString("Current Value: " + x,10,180);
    }
}


/*


*/
Output

No comments:

Post a Comment