— Scott McNealy, Sun Microsystems Chairman, President and ceo



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

making a drawing 
panel
import java.awt.*;
import javax.swing.*;
class MyDrawPanel extends JPanel {

public void paintComponent(Graphics g) {
g.setColor(Color.orange);
g.fillRect(20,50,100,100);
}
}
you need both of these
Make a subclass of JPanel, a widget 
that you can add to a frame just like 
anything else. Except this one is your 
own customized widget.
This is the Big Important 
Graphics method. 
You will NEVER call this yourself. The 
system calls it and says, “Here’s a nice 
fresh drawing surface, of type Graphics, 
that you may paint on now.”.
Imagine that ‘g’ is a painting machine. You’re 
telling it what color to paint with and then 
what shape to paint (with coordinates for 
where it goes and how big it is)


getting 
gui
you are here
4
365
Let’s look at a few more things you can do in paintComponent(). 
The most fun, though, is when you start experimenting yourself. 
Try playing with the numbers, and check the API for class 
Graphics (later we’ll see that there’s even more you can do besides 
what’s in the Graphics class).
Fun things to do in paintComponent()
public void paintComponent(Graphics g) {
Image image = new ImageIcon(“catzilla.jpg”).getImage();
g.drawImage(image,3,4,this);

}
public void paintComponent(Graphics g) {

g.fillRect(0,0,this.getWidth(), this.getHeight());

int red = (int) (Math.random() * 255);
int green = (int) (Math.random() * 255);
int blue = (int) (Math.random() * 255);
Color randomColor = new Color(red, green, blue);

Download 40,57 Mb.

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