|
|
Web Configuration:
<applet code="AdjustScroll.class"
codebase="applet" width=200 height=40>
</applet>
Source Code:
/*
* AdjustScroll.java
*
* Created on November 2, 2002, 9:37 PM
*
* This example demonstrates how to get adjustment events from
* a component that fires them. The example creates a horizontal
* scrollbar and listens for adjustment events from the scrollbar
* In response to an adjustment event, the specifics of the event
* are shown as the label.
*/
import java.awt.*;
import java.awt.event.*;
public class AdjustScroll extends java.applet.Applet implements
AdjustmentListener{
Label result = new Label();
public void init () {
Scrollbar sb = new Scrollbar(Scrollbar.HORIZONTAL);
// Listen for adjustment events
sb.addAdjustmentListener(this);
setLayout(new BorderLayout());
add(sb, BorderLayout.CENTER);
add(result, BorderLayout.SOUTH);
}
public void adjustmentValueChanged(AdjustmentEvent e) {
String s = "adjustable: " + e.getAdjustable();
switch (e.getAdjustmentType()){
case AdjustmentEvent.BLOCK_DECREMENT:
s = "BLOCK_DECREMENT";
break;
case AdjustmentEvent.BLOCK_INCREMENT:
s = "BLOCK_INCREAMENT";
break;
case AdjustmentEvent.TRACK:
s = "TRACK";
break;
case AdjustmentEvent.UNIT_DECREMENT:
s = "UNIT_DECREMENT";
break;
case AdjustmentEvent.UNIT_INCREMENT:
s = "UNIT_INCREMENT";
break;
}
result.setText(s);
}
} |