-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUseAdjustmentEvent.java
43 lines (40 loc) · 1 KB
/
UseAdjustmentEvent.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import java.applet.Applet;
public class UseAdjustmentEvent extends Applet implements AdjustmentListener
{
Scrollbar s;
TextArea txtValue;
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);
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));
}
}
}