— Scott McNealy, Sun Microsystems Chairman, President and ceo


graphics.setColor(Color.blue)



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

graphics.setColor(Color.blue); 
g.fillRect(20,50,100,120);
ß
To draw a .jpg, construct an Image using: 
Image image = new ImageIcon(“catzilla.
jpg”).getImage(); 
and draw the imagine using: 
g.drawImage(image,3,4,this);
ß
The object referenced by the Graphics parameter 
to paintComponent() is actually an instance of the 
Graphics2D class. The Graphics 2D class has a variety 
of methods including: 
fill3DRect(), draw3DRect(), rotate(), scale(), shear(), 
transform()
ß
To invoke the Graphics2D methods, you must cast the 
parameter from a Graphics object to a Graphics2D 
object: 
Graphics2D g2d = (Graphics2D) g; 
 EVENTS


getting 
gui
you are here
4
369
Let’s hook up an event to a change in our drawing panel. We’ll make the circle 
change colors each time you click the button. Here’s how the program flows:
We can get an event.
We can paint graphics.
But can we paint graphics 
when we get an event?
1
2
Voila! A new color is painted because 
paintComponent() runs again, filling the 
circle with a random color.
The frame is built with the two widgets 
(your drawing panel and a button). A 
listener is created and registered with 
the button. Then the frame is displayed 
and it just waits for the user to click.
Start the app 
The user clicks the button and the 
button creates an event object and 
calls the listener’s event handler.
3
4
The event handler calls repaint() on the 
frame. The system calls paintComponent() 
on the drawing panel. 



Download 40,57 Mb.

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