河南成教 / Java程序设计
[简答题] 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);
}
}
class MyWindow extends JFrame implements AdjustmentListener{
private JTextField text;
MyWindow(String s){
super(s);
MyScrollBar myBar=new MyScrollBar(10,10,0,255);
Container con=this. getContentPane();
con. setLayout(new GridLayout(2,1));
this. setSize(200,100);
this. setLocation(100,100);
myBar.addAdjustmentListener(this);
text=new JTextField("",20);
con. add(text);con.add(myBar);
this.setVisible(true);
}
public void adjustmentValueChanged(AdjustmentEvent e){
MyScrollBar myBar=(MyScrollBar)e.getAdjustable();
text.setText(""+myBar.getValue());
}
}
public class Class1{
public static void main(String[]args){
MyWindow myWindow=new MyWindow("text5_4");
}
}
class MyScrollBar extends JscrollBar{
public MyScrollBar(int init, int len, int low, int high){
super(JScrollBar. HORIZONTAL, init,len,low,high);
}
}
class MyWindow extends JFrame implements AdjustmentListener{
private JTextField text;
MyWindow(String s){
super(s);
MyScrollBar myBar=new MyScrollBar(10,10,0,255);
Container con=this. getContentPane();
con. setLayout(new GridLayout(2,1));
this. setSize(200,100);
this. setLocation(100,100);
myBar.addAdjustmentListener(this);
text=new JTextField("",20);
con. add(text);con.add(myBar);
this.setVisible(true);
}
public void adjustmentValueChanged(AdjustmentEvent e){
MyScrollBar myBar=(MyScrollBar)e.getAdjustable();
text.setText(""+myBar.getValue());
}
}
public class Class1{
public static void main(String[]args){
MyWindow myWindow=new MyWindow("text5_4");
}
}
参考答案: