public class ScrollbarSample extends Applet implements AdjustmentListener
This Java file can be compiled using
-source 1.3 -target 1.3
Modifier and Type | Class and Description |
---|---|
(package private) class |
ScrollbarSample.secondListener
This class is used to listen to the pull-down menu used to select
the color of the object being drawn.
|
Applet.AccessibleApplet
Panel.AccessibleAWTPanel
Container.AccessibleAWTContainer
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
Modifier and Type | Field and Description |
---|---|
(package private) Scrollbar |
a
Object for the scrollbar.
|
int |
angle
Integer value indicating the angle to be used in creating the partial
arc of the circle.
|
(package private) Choice |
choiceBox |
(package private) ScrollbarSample.secondListener |
colorListener
Object listening for changes to the pull-down menu.
|
(package private) Canvas |
screen1
Object representing the partial circle which is to be drawn.
|
private static long |
serialVersionUID |
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
Constructor and Description |
---|
ScrollbarSample() |
Modifier and Type | Method and Description |
---|---|
void |
adjustmentValueChanged(AdjustmentEvent e)
Method called by the system every time the position
on the scrollbar is changed.
|
void |
init()
The init method is called when the applet is started.
|
void |
paint(Graphics g)
Method to be executed when repainting the window.
|
destroy, getAccessibleContext, getAppletContext, getAppletInfo, getAudioClip, getAudioClip, getCodeBase, getDocumentBase, getImage, getImage, getLocale, getParameter, getParameterInfo, isActive, isValidateRoot, newAudioClip, play, play, resize, resize, setStub, showStatus, start, stop
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getAlignmentX, getAlignmentY, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getInsets, getLayout, getListeners, getMaximumSize, getMinimumSize, getMousePosition, getPreferredSize, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, paramString, preferredSize, print, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, removeNotify, setComponentZOrder, setFocusCycleRoot, setFocusTraversalKeys, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setFont, setLayout, transferFocusDownCycle, update, validate, validateTree
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, disable, disableEvents, dispatchEvent, enable, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBaseline, getBaselineResizeBehavior, getBounds, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphics, getGraphicsConfiguration, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocation, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getToolkit, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, printAll, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, reshape, revalidate, setBackground, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeysEnabled, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setMaximumSize, setMinimumSize, setName, setPreferredSize, setSize, setSize, setVisible, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
private static final long serialVersionUID
public int angle
Since this is a public field, it can be read and modified by other objects.
ScrollbarSample.secondListener colorListener
The addItemListener method that is called in the init method for the class links the listening object to the object which represents the pull-down menu.
Scrollbar a
This notation allows you to both specify the parameters for setting up the scrollbar while overriding some of the methods used in the object.
The addAdjustment listener method in the init method for the class links the object for the scrollbar to the object listening to the scrollbar.
Canvas screen1
This notation allows the the Canvas class to be subclassed at the same time the object is instantiated by overriding methods. The Canvas object doesn't do anything useful unless the methods are overridden in a subclass.
In this case, overriding the paint method adds the instructions that draw the partial circle according to the rules obtained from two listeners.
Since the subclass is created but not named, this is an anonymous subclass.
Canvas
public ScrollbarSample()
public void init()
The pull-down menu is represented by the choiceBox object,
while the statement
choiceBox.addItemListener(colorListener)
links the object for the pull-down menu to the object
listening for changes to the pull-down menu.
The statement
a.addAdjustmentListener(this)
means that
changes to the scrollbar (object a) cause the
adjustmentValueChanged method of this class to
executed.
public void adjustmentValueChanged(AdjustmentEvent e)
adjustmentValueChanged
in interface AdjustmentListener
public void paint(Graphics g)
The paint method is called whenever it is necessary to redraw the contents of the window created by the applet. This could be because the window is resized, covered, or uncovered, or it could be because some object calls the repaint method.
It should be noted that the object for drawing the partial circle above has its own paint method.