— Scott McNealy, Sun Microsystems Chairman, President and ceo


frame.getContentPane().add(button)



Download 40,57 Mb.
Pdf ko'rish
bet342/555
Sana26.05.2022
Hajmi40,57 Mb.
#609235
1   ...   338   339   340   341   342   343   344   345   ...   555
Bog'liq
Head First Java (Kathy Sierra, Bert Bates) (z-lib.org)

frame.getContentPane().add(button);
ß
Unlike most other components, the JFrame doesn’t let 
you add to it directly, so you must add to the JFrame’s 
content pane.
ß
To make the window (JFrame) display, you must give it 
a size and tell it be visible: 
frame.setSize(300,300); 
frame.setVisible(true);
ß
To know when the user clicks a button (or takes some 
other action on the user interface) you need to listen for 
a GUI event.
ß
To listen for an event, you must register your interest 
with an event source. An event source is the thing (but-
ton, checkbox, etc.) that ‘fires’ an event based on user 
interaction.
ß
The listener interface gives the event source a way 
to call you back, because the interface defines the 
method(s) the event source will call when an event 
happens.
ß
To register for events with a source, call the source’s 
registration method. Registration methods always take 
the form of:
 addListener. To register for a 
button’s ActionEvents, for example, call: 
button.addActionListener(this);
ß
Implement the listener interface by implementing all of 
the interface’s event-handling methods. Put your event-
handling code in the listener call-back method. For 
ActionEvents, the method is: 
public void actionPerformed(ActionEvent 
event) {
button.setText(“you clicked!”);
}
ß
The event object passed into the event-handler method 
carries information about the event, including the source 
of the event.
 BULLET POINTS
 GRAPHICS
ß
You can draw 2D graphics directly on to a widget.
ß
You can draw a .gif or .jpeg directly on to a widget.
ß
To draw your own graphics (including a .gif or .jpeg), 
make a subclass of JPanel and override the paintCom-
ponent() method.
ß
The paintComponent() method is called by the GUI 
system. YOU NEVER CALL IT YOURSELF. The argu-
ment to paintComponent() is a Graphics object that 
gives you a surface to draw on, which will end up on 
the screen. You cannot construct that object yourself.
ß
Typical methods to call on a Graphics object (the paint-
Component paramenter) are: 

Download 40,57 Mb.

Do'stlaringiz bilan baham:
1   ...   338   339   340   341   342   343   344   345   ...   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