滑块

来源:互联网 发布:山东学前教育网络平台 编辑:程序博客网 时间:2024/04/28 22:42

//SliderDeom.java

//滑块,其中随着滑块的滑动,前面的数值不会改变,现在不会解快。 

//<applet code=SliderDemo width=200 height=100>
//</applet>

import javax.swing.*;
import java.awt.*;

public class SliderDemo extends JApplet
{
 JTextField txt=new JTextField();
 JSlider sd=new JSlider(JSlider.HORIZONTAL,0,100,60);//四个参数,水平,开始值0,最后值100,初始值60。
 
 public void init(){
  Container cp=getContentPane();
  cp.setLayout(new FlowLayout());
  cp.add(txt);
  sd.setValue(40);//设置滑块的值为40
  sd.setPaintTicks(true);//显示刻度。
  sd.setMajorTickSpacing(20);//主刻度线
  sd.setMinorTickSpacing(5);//次刻度线
  sd.setPaintLabels(true);//在标尺下线示刻度
  cp.add(sd);
  txt.setText(Integer.toString(sd.getValue()));
 }
}

 

 

 

原创粉丝点击