问答题

阅读下列程序,请回答下面的问题:
import javax.swing.* ;import java.awt. * ;import java.awt.event. *;
class MyScrollBar extends JScrollBar }
public MyScrollBar(int init,int len,int low,int high) {
super (JScrollBar.HORIZONTAL,init,len,low,high);
}
public Dimension getPreferredSize(){
return new Dimension(125,20);
}
}
class MyWindow extends JFrame implements AdjustmentListener {
private JTextField t; MyScrollBar bar;
MyWindow(String s){
super(s);
bar=new MyScrollBar(10,10,0,255);
Container con=this.getContentPane ();
con.setLayout (new GridLayout (2,1));
this.setSize (250, 100) ;this.setLocation (100, 100);
bar. addAdjustmentListener(this);
t=new JTextField(" ",20); con.add(bar) ;con.add(t);
this. setVisible (true) ;this.pack ();
}
public void adjustmentValueChanged (AdjustmentEvent e) {
MyScrollBar myBar=(MyScrolIBar) e.getAdjustable();
t.setText (myBar.getValue ());
}
}
public class Test34 {
public static void main(String[ ] args) {
new MyWindow("Test34窗口");
}
} 该程序的功能是什么

【参考答案】

移动滚动条上的滑块,在文本框中显示滑块对应的值。