java AdjustmentListener,Scrollbar的使用
?
package gui.event;import java.awt.*;import java.awt.event.*;import java.applet.Applet;public class UseAdjustmentEvent extends Applet implements AdjustmentListener {/** * */private static final long serialVersionUID = 1L;private Scrollbar s;private TextArea txtValue;private Panel p;public void init() {s = new Scrollbar(Scrollbar.HORIZONTAL, 0, 1, 10, 36);// 添加监听者s.addAdjustmentListener(this);txtValue = new TextArea(5, 25);// 界面布局p = new Panel(new BorderLayout());p.add(s, BorderLayout.NORTH);p.add(txtValue, BorderLayout.SOUTH);this.add(p);}public void start() {}public void adjustmentValueChanged(AdjustmentEvent e) {int value;Font oldF;if (e.getAdjustable() == s) {// 得到滚动条的值value = e.getValue();// 将值写入文本区域txtValue.setText(new Integer(value).toString());// 按照滚动条的值设置字体oldF = txtValue.getFont();txtValue.setFont(new Font(oldF.getName(), oldF.getStyle(), value));}}}?