— Scott McNealy, Sun Microsystems Chairman, President and ceo



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

instance of the Graphics2D class. 
Why do you care? Because there are things you can do with 
a Graphics2D reference that you can’t do with a Graphics 
reference. A Graphics2D object can do more than a Graphics 
object, and it really is a Graphics2D object lurking behind the 
Graphics reference.
Remember your polymorphism. The compiler decides which 
methods you can call based on the reference type, not the 
object type. If you have a Dog object referenced by an Animal 
reference variable:
Animal a = new Dog();
You can NOT say:
a.bark();
Even though you know it’s really a Dog back there. The 
compiler looks at ‘a’, sees that it’s of type Animal, and finds 
that there’s no remote control button for bark() in the Animal 
class. But you can still get the object back to the Dog it really is 
by saying:
Dog d = (Dog) a;
d.bark();
So the bottom line with the Graphics object is this:
If you need to use a method from the Graphics2D class, you 
can’t use the the paintComponent parameter (‘g’) straight 
from the method. But you can cast it with a new Graphics2D 
variable.
Graphics2D g2d = (Graphics2D) g;
Methods you can call on 

Graphics2D
reference:
fill3DRect()
draw3DRect()
rotate()
scale()
shear()
transform()
setRenderingHints()
(these are not complete method lists, 
check the API for more)
To cast the 
Graphics2D
object to 

Graphics2D
reference:
Graphics2D g2d = (Graphics2D) g;


getting 
gui
you are here
4
367
public void paintComponent(Graphics g) {

Download 40,57 Mb.

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