Simple scroller

import java.awt.*;
import java.applet.Applet;
// Import the event library
import java.awt.event.*;
// This applet demonstrates an event by placing a scrollbar in the applet window
public class FirstEvent extends Applet implements AdjustmentListener

//Declare an integer for the current value and a Scrollbar object
private Scrollbar slider;
private int sliderValue = 0;
public void init()

// Setup the scrollbar so it starts with an initial value of 0
slider = new Scrollbar(Scrollbar.HORIZONTAL, 0,1,0,100);
// Add the slider object
// Attach a listener to the slider. This in effect causes the
// adjustmentValueChanged method below to be invoked.


public void paint(Graphics g)

// Display the current value of the slider
g.drawString("Current value is " + sliderValue, 100, 100);

public void adjustmentValueChanged (AdjustmentEvent e)

// Get the current value of the scrollbar and put it into
// sliderValue

sliderValue = slider.getValue();
// Invoke the paint method



Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License