java.lang.Objectgreenfoot.Actor
Slider
public class Slider
A slider to allow a user to select a number in a given range.
Create a Slider by calling new
(for the default size)
or Slider()
new
(for a custom size).
Set teh maximum value that the user can select by calling
Slider(int, int)
setMaximumValue(int)
, set the initial value by calling
setValue(int)
and add it to the world by calling the
addObject(Actor, int, int) method on the World.
You can also set how the slider should display by calling the other methods.
This should be done before adding the slider to the world, but does not need to be
Constructor Summary | |
---|---|
Slider()
Create a new slider with the default size. |
|
Slider(int width,
int height)
Create a new slider. |
Method Summary | |
---|---|
void |
act()
This method is called by Greenfoot, and updates the slider if the user has dragged the slider. |
void |
addedToWorld(greenfoot.World world)
This method is called by the World class when the slider is added to the world. |
int |
getMajorSections()
Get the number of major sections that are marked. |
int |
getMaximumValue()
Get the current maximum value which the user can select |
int |
getMinorSections()
Get the number of minor sections that are marked. |
int |
getValue()
Get the current value. |
boolean |
isShowingPercentage()
Check whether the slider is set to display the value as a percentage. |
boolean |
isShowingValue()
Check whether the slider is set to display the value. |
void |
setMajorSections(int sections)
Set the number of major sections to be marked. |
void |
setMaximumValue(int value)
Set the maximum value that the user can select. |
void |
setMinorSections(int sections)
Set the number of minor sections to be marked per major secton. |
void |
setValue(int value)
Set the current selected value of the slider. |
void |
showPercentage(boolean show)
Set whether the value will be displayed next to the slider as a percentage. |
void |
showValue(boolean show)
Set whether the value should be displayed next to the slider. |
Methods inherited from class greenfoot.Actor |
---|
getImage, getIntersectingObjects, getNeighbours, getObjectsAtOffset, getObjectsInRange, getOneIntersectingObject, getOneObjectAtOffset, getRotation, getWorld, getX, getY, intersects, setImage, setImage, setLocation, setRotation |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public Slider()
public Slider(int width, int height)
width
- The width of the slider in pixelsheight
- The height of th slider in pixelsMethod Detail |
---|
public void act()
act
in class greenfoot.Actor
public void addedToWorld(greenfoot.World world)
addedToWorld
in class greenfoot.Actor
world
- The worldpublic int getMajorSections()
setMajorSections(int)
public int getMaximumValue()
public int getMinorSections()
setMinorSections(int)
public int getValue()
public boolean isShowingPercentage()
showPercentage(boolean)
,
isShowingValue()
public boolean isShowingValue()
showValue(boolean)
,
isShowingPercentage()
public void setMajorSections(int sections)
sections
- The number of major sections to displaysetMinorSections(int)
public void setMaximumValue(int value)
value
- The new maximum valuepublic void setMinorSections(int sections)
sections
- The number of minor sections to mark per major sectionsetMajorSections(int)
public void setValue(int value)
value
- The new valuepublic void showPercentage(boolean show)
showValue(boolean)
. If
both are set to true, the percentage is shown. If both are true and
showPercentage(false) is called then the value will be shown. If both
are true and showValue(false) is called then neither the value nor
percentage is shown.
show
- true if the value should be displayed as a percentage of
the maximum value, false if it should not.showValue(boolean)
,
isShowingPercentage()
public void showValue(boolean show)
shoePercentage(boolean)
will also be set to false.
show
- true if the value should be displayed as text,
false if it should not beshowPercentage(boolean)