import java.applet.*; import java.awt.*; import java.awt.event.*; public class AnAppletWithScrollbar extends Applet implements AdjustmentListener { public void init() { scrollbar = new Scrollbar(Scrollbar.HORIZONTAL, 50, 0, 0, 100); add(scrollbar); scrollbar.addAdjustmentListener(this); textField = new TextField(3); textField.setEditable(false); add(textField); } public void adjustmentValueChanged(AdjustmentEvent e) { textField.setText(scrollbar.getValue()+""); } Scrollbar scrollbar; TextField textField; }
Scrollbar
Scrollbar
is an interface component that allows the user to easily move within
a specified range of values
getValue
, setValue
methods
adjustment
event
and the applet registers as an AdjustmentListener
.
adjustmentValueChanged
init
Method
visible
argument to the
constructor to 0
TextField
is created and placed on the applet
adjustmentValueChanged
getSource
method can
be used, just as in actionPerformed
getValue
must be converted to a String
Scrollbar
class
Place the following applets on the same page:
AnAppletWithScrollbar
so that the text field initially displays the intial value
of the scrollbar.
AnAppletWithCanvas (#1), making the following changes:
- Replacing the larger/smaller buttons with a pair of scroll bars-- one horizintal, the other vertical.
- The circle is now an oval-- using the horizontal scroll bar modifies the width of the oval; the vertical
scrollbar modifies the height
- The up/down buttons should remain as buttons