— Scott McNealy, Sun Microsystems Chairman, President and ceo



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

Graphics2D g2d = (Graphics2D) g;
GradientPaint gradient = new GradientPaint(70,70,Color.blue, 150,150, Color.orange);

g2d.setPaint(gradient);
g2d.fi llOval(70,70,100,100);
}
Because life’s too short to paint the 
circle a solid color when there’s a 
gradient blend waiting for you.
public void paintComponent(Graphics g) {
Graphics2D g2d = (Graphics2D) g;

int red = (int) (Math.random() * 255);
int green = (int) (Math.random() * 255);
int blue = (int) (Math.random() * 255);
Color startColor = new Color(red, green, blue);
red = (int) (Math.random() * 255);
green = (int) (Math.random() * 255);
blue = (int) (Math.random() * 255);
Color endColor = new Color(red, green, blue);
GradientPaint gradient = new GradientPaint(70,70,startColor, 150,150, endColor);
g2d.setPaint(gradient);
g2d.fi llOval(70,70,100,100);
}
it’s really a Graphics2D object 
masquerading as a mere Graphics 
object.
cast it so we can call something that 
Graphics2D has but Graphics doesn’t
this sets the virtual paint brush to a 
gradient instead of a solid color
starting pointstarting color ending point ending color
the fillOval() method really means “fill 
the oval with whatever is loaded on your 
paintbrush (i.e. the gradient)”
this is just like the one above, 
except it makes random colors for 
the start and stop colors of the 
gradient. Try it! 


368
 
chapter 12
events 
and graphics
ß
To make a GUI, start with a window, usually a JFrame 
JFrame frame = new JFrame();
ß
You can add widgets (buttons, text fields, etc.) to the 
JFrame using: 

Download 40,57 Mb.

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