-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUseLabel.java
More file actions
34 lines (32 loc) · 712 Bytes
/
Copy pathUseLabel.java
File metadata and controls
34 lines (32 loc) · 712 Bytes
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
import java.awt.*;
import java.applet.*;
import java.applet.Applet;
public class UseLabel extends Applet
{
String str1 = new String();
int i1 = 0;
Label l1; //声明对象
Label l2;
Label l3;
public void init()
{
l1 = new Label();
l2 = new Label("标签对象2");
l3 = new Label("标签对象3", Label.CENTER);
this.add(l1);
this.add(l2);
this.add(l3);
}
public void start()
{
l1.setText("标签对象1");
str1 = l2.getText();
i1 = l3.getAlignment();
repaint();
}
public void paint(Graphics g)
{
g.drawString("获取第二个对象的文本: " + str1, 40, 60);
g.drawString("标签对象3的对齐方式: " + i1, 40, 80);
}
}