— Scott McNealy, Sun Microsystems Chairman, President and ceo



Download 40,57 Mb.
Pdf ko'rish
bet348/555
Sana26.05.2022
Hajmi40,57 Mb.
#609235
1   ...   344   345   346   347   348   349   350   351   ...   555
Bog'liq
Head First Java (Kathy Sierra, Bert Bates) (z-lib.org)

// with the color button and the other with the label button


// close class
class ColorButtonListener implements ActionListener {
public void actionPerformed(ActionEvent event) {
frame.repaint();
}
}
class LabelButtonListener implements ActionListener {
public void actionPerformed(ActionEvent event) {
label.setText(“That hurt!”);
}
}
Problem! This class has no reference to the variable ‘label’
Won’t work! This class doesn’t have a reference to 
the ‘frame’ variable of the MyGui class
multiple 
listeners
How do you get action events for t wo different buttons, 
when each button needs to do something different?


getting 
gui
you are here
4
375
Wouldn’t it be wonderful if you 
could have two different listener classes, 
but the listener classes could access the 
instance variables of the main GUI class, 
almost as if the listener classes 
belonged 
to the other class. Then you’d have the best 
of both worlds. Yeah, that would be dreamy. 
But it’s just a fantasy...


376
 
chapter 12
You can have one class nested inside another. It’s easy. 
Just make sure that the definition for the inner class is 
inside the curly braces of the outer class.
Inner class to the rescue!
class MyOuterClass {

class MyInnerClass {
void go() {
}


Simple inner class:
class MyOuterClass {
private int x;


Download 40,57 Mb.

Do'stlaringiz bilan baham:
1   ...   344   345   346   347   348   349   350   351   ...   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