Java Example Program/ Sample Source Code
import java.awt.BorderLayout;
import java.awt.Frame;
import java.awt.Label;
import java.awt.Scrollbar;
import java.awt.event.AdjustmentEvent;
import java.awt.event.AdjustmentListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
public class GetAdjustableExample {
public static void main(String[] args) {
Frame frame = new Frame("AdjustmentEventExample");
Label label = new Label("Welcome To JavaTips.net");
Scrollbar hbar = new Scrollbar(Scrollbar.HORIZONTAL, 30, 20, 0, 300);
Scrollbar vbar = new Scrollbar(Scrollbar.VERTICAL, 30, 40, 0, 300);
frame.setLayout(new BorderLayout());
frame.add(hbar, BorderLayout.SOUTH);
frame.add(vbar, BorderLayout.EAST);
frame.add(label, BorderLayout.CENTER);
AdjustmentListener adjustmentListener = new MyAdjustmentListener();
hbar.addAdjustmentListener(adjustmentListener);
vbar.addAdjustmentListener(adjustmentListener);
frame.setSize(400, 400);
frame.setVisible(true);
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
}
}
class MyAdjustmentListener implements AdjustmentListener {
public void adjustmentValueChanged(AdjustmentEvent ae) {
System.out.println(ae.getAdjustable());
System.out.println(ae.getValue());
System.out.println(ae.getAdjustmentType());
System.out.println(ae.getValueIsAdjusting());
System.out.println(ae.paramString());
}
} |
|
|