L
L
p
p
t
t
r
r
T
T
CAO
Duc
Thong
–
Thanglong
University
2
N
N
i
i
d
AWT
Qun
lý
trình
bày
lý
kin
3
T
T
h
h
a
Abstract
Windowing
Toolkit
AWT
cho
phép
o
các
thành
phn
a
phn
a
n
a
AWT
t
cha
(Container)
Thành
phn
ch
(Font),
kin
(Event)
4
T
T
h
h
v
v
i
i
n
n
A
A
W
W
T
Toolk
i
t
MenuComponent
XXXLayout
CheckboxGroup
Component
MenuBar
MenuItem
n
n
A
A
W
W
T
T
Component
Button
CanvasTextComponent
Panel
Window
Scroll
Pane TextArea
TextField
á
á
c
c
t
t
h
h
à
à
n
n
h
h
p
p
h
h
n
n
A
A
W
W
T
T
hin
th
c
trên
màn
hình
và
có
th
ng
tác
i
ngi
dùng
Component:
button,
checkbox,
scrollbar…
t
phng
thc
n
a
Component
a
Component
(Rectangle)
getFont():
tr
font
hin
i
a
Component
getForeGround():
kiu
int)
7
C
C
á
á
c
c
t
t
h
h
à
à
n
n
h
h
p
p
h
h
n
n
getSize():
tr
kích
thc
a
Component
(Dimenstion)
getWidth():
tr
chiu
isEnable():
boolean
paint(Graphics):
chu
trách
nhim
hin
th
component
repaint():
c
i
c
c
t
t
h
h
à
à
n
n
h
h
p
p
h
h
n
n
A
A
W
W
T
T
th
t
các
thành
phn
giao
din
t
loi
Container:
Panel,
Frame,
Dialog
t
Component
vào
Container
ta
ng
phng
thc
add(Component)
Container
ng
t
h
h
p
p
h
h
n
n
A
A
W
W
T
T
Frame
Tha
là
Container
o
Frame
Frame()
Frame(String
title)
Ví
T
Frame
import java.awt.*;
public class UseLessFrame
extends
Frame {
public
UseLessFrame(){
super("Useless
Frame");
setS
ize(300,200);
setVisible(true);
}
public static
void
h
h
n
n
A
A
W
W
T
T
Frame
12
X
X
kin
là
gì
Khi
ngi
dùng
thc
hin
t
hành
ng
i
ng
mô
nhng
gì
ã
y
ra
i
tác
ng
aButtonActionEvent
EventHandler
actionP
erformed(ActionEvent
e){
//Do
something
}
13
X
X
l
l
ý
ý
c
c
Là
ngun
sinh
ra
kin.
kin
c
sinh
ra
i
ng
thc,
nó
nhn
t
i
ng
event,
gii
mã
và
lý
các
ng
p
nghe
kin
(listener)
t
p
nghe
có
th
lý
nghe
t
ngun
sinh
ra
kin
có
th
có
nhiu
p
nghe
l
l
ý
ý
c
c
á
á
c
c
s
s
k
k
i
i
n
n
TextField t
f1
=
new
TextField(5);
TextField t
f2
=
new
TextField(5);
Button btnResult =
new
Button("Dou
ble i
s");
Button ext = ne
w
Button("exit");
public EventTest(String title) {
super(title);
setLayout(new
FlowLayout());
btnResult.addActionListener(this);
ext.addActionListener(this);
add(lab);
add(tf1);
add(btnR
esult);
n
n
Ví
lý
kin
public
new
EventTest("Event
handling");
t.setS
ize(300,
200);
t.setVisible(true);
}
}
16
X
X
l
l
ý
ý
c
c
á
á
c
c
s
kin 17
X
X
l
l
ý
ý
c
c
á
á
c
c
s
s
k
k
i
java.awt.AWTEvent
ActionEvent
java.awt.event AdjustmentEvent ComponentEvent
ItemEvent
FocusEvent
InputEvent
ContainerEvent
KeyEvent
k
k
i
i
n
n
Mô
kin19
X
Các
loi
Listener
ActionListener
AdjustmentListener
E
v
ContainerListener
e
n
FocusListener
t
L
i
c
c
á
á
c
c
s
s
k
k
i
i
n
n
ng
ký
Ví
i
nút
Button
addActionListener(ActionListener)
Ví
i
danh
sách
List
addActionListener(A
ctionListener)
addItemListener(Ite
mListener)
Cài
t
qun
lý
kin
Xác
nh
i
ng
ng
ng
i
i
ng
mà
ta
n
qun
lý
(object)
Xác
nh
i
ng
nghe
cho
i
ng
gây
ra
kin
X
X
l
l
ý
ý
c
c
á
qun
lý
kin
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class TestButton {
private Frame f;
private Button b;
public TestButton(){
f
=
new
Frame("Test");
b
=
new
Button("Press
me");
b.setActionCommand("ButtonPressed");
}
k
k
i
i
n
n
}
22
X
X
l
l
ý
ý
c
c
á
á
c
c
s
s
kin
public static
void
main(String[]
args){
TestButton test =
new
TestButton();
test.init
(
);
}
}
class ButtonHandler implements ActionListener{
public
void
actionPerformed(ActionEvent e) {
n
n
24
Ví
qun
lý
kin