import java.awt.*;
import java.awt.event.*;

        // Display a 1..daysInYear calendar with a Scrollbar slider.
class DayOfYear extends Frame implements AdjustmentListener {
    public DayOfYear(){
        final int width = 400, height = 75;
        setSize(width,height);
        setBackground(Color.white);

        // The maximum and minimum values on the scale,
        // allowing for leap years.
        final int firstDay = 1, daysInYear = 366;
        // The slider represents a week.
        final int daysInWeek = 7;
        final int sliderWidth = daysInWeek;

        Scrollbar bar =
                new Scrollbar(Scrollbar.HORIZONTAL,
                              firstDay,
                              sliderWidth,
                              // The range - allow for the slider's width.
                              firstDay,daysInYear+sliderWidth);

        // Set increments for clicking in the scrollbar and
        // using the end adjusters.
        bar.setBlockIncrement(daysInWeek);
        bar.setUnitIncrement(1);

        // Let me know when the bar is moved.
        bar.addAdjustmentListener(this);

        // Create a label for the day display.
        // Allow enough space for the maximum day.
        Label display = new Label(labelPrefix+daysInYear,Label.CENTER);
        setDayDisplay(display);

        // Display the label and scrollbar one above the other.
        Panel panel = new Panel();
        final int rows = 2, cols = 1;
        panel.setLayout(new GridLayout(rows,cols));
        panel.add(display);
        panel.add(bar);

        add(panel);

        // Set the label to the initial value.
        display.setText(labelPrefix+bar.getValue());
    }

    // Implement AdjustmentListener
    public void adjustmentValueChanged(AdjustmentEvent e){
        // Get the bar on which the adjustment happened.
        Adjustable bar = e.getAdjustable();

        // Get the new value.
        int value = bar.getValue();

        // Change the display label.
        Label display = getDayDisplay();
        display.setText(labelPrefix+value);
    }

    protected Label getDayDisplay(){
        return dayDisplay;
    }

    protected void setDayDisplay(Label label){
        dayDisplay = label;
    }

    // Prefix for the day number display.
    private static final String labelPrefix = "Day: ";
    // A display for the current day.
    private Label dayDisplay;
}
