【发布时间】:2016-10-26 02:59:30
【问题描述】:
这段代码的作用是每当滑块的旋钮在 0-20 和 20-50 之间经过时打印一条消息(当旋钮位于 1、2、3、4 等时打印一条消息)。我需要的是当旋钮在这些范围之间时只打印一次。
public void stateChanged(ChangeEvent e)
{
int sliderValue = jslider.getValue(); //This method returns the value of the Slider!
if(sliderValue >= 0 && sliderValue <= 20)
{
System.out.println("Between 0 and 20");
}
else if (sliderValue > 20 && sliderValue <= 50)
{
System.out.println("You're 20 - 50");
}
}
【问题讨论】: