— Scott McNealy, Sun Microsystems Chairman, President and ceo



Download 40,57 Mb.
Pdf ko'rish
bet331/555
Sana26.05.2022
Hajmi40,57 Mb.
#609235
1   ...   327   328   329   330   331   332   333   334   ...   555
Bog'liq
Head First Java (Kathy Sierra, Bert Bates) (z-lib.org)

user interface 
events


getting 
gui
you are here
4
357
Imagine you want the text on the button to 
change from click me to I’ve been clicked when 
the user presses the button. First we can write a 
method that changes the text of the button (a 
quick look through the API will show you the 
method):
Getting a user event
public void changeIt() {
button.setText(“I’ve been clicked!”);
}
But now what? How will we know when this 
method should run? How will we know when the 
button is clicked?
In Java, the process of getting and handling a 
user event is called event-handling. There are 
many different event types in Java, although 
most involve GUI user actions. If the user clicks 
a button, that’s an event. An event that says 
“The user wants the action of this button to 
happen.” If it’s a “Slow Tempo” button, the user 
wants the slow-tempo action to occur. If it’s a 
Send button on a chat client, the user wants the 
send-my-message action to happen. So the most 
straightforward event is when the user clicked 
the button, indicating they want an action to 
occur. 
With buttons, you usually don’t care about any 
intermediate events like button-is-being-pressed 
and button-is-being-released. What you want to 
say to the button is, “I don’t care how the user 
plays with the button, how long they hold the 
mouse over it, how many times they change their 
mind and roll off before letting go, etc. Just tell 
me when the user means business! 
In other words, 
don’t call me unless the user clicks in a way that 
indicates he wants the darn button to do what it 
says it’ll do!”
First, the button needs to know 
that we care.
your code
butt
o
n
ob
jec

Hey button, I care about 
what happens to you.

Download 40,57 Mb.

Do'stlaringiz bilan baham:
1   ...   327   328   329   330   331   332   333   334   ...   555




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish