— Scott McNealy, Sun Microsystems Chairman, President and ceo



Download 40,57 Mb.
Pdf ko'rish
bet329/555
Sana26.05.2022
Hajmi40,57 Mb.
#609235
1   ...   325   326   327   328   329   330   331   332   ...   555
Bog'liq
Head First Java (Kathy Sierra, Bert Bates) (z-lib.org)

getting 
gui
you are here
4
355
import javax.swing.*;
public class SimpleGui1 {
public static void main (String[] args) {
JFrame frame = new JFrame();
JButton button = new JButton(“click me”);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().add(button);
frame.setSize(300,300);
frame.setVisible(true);
}
}
Whoa! That’s a 
Really Big Button.
The button fills all the 
available space in the frame. 
Later we’ll learn to control 
where (and how big) the 
button is on the frame.
Your first GUI: a button on a frame
don’t forget to import this 
swing package
(you can pass the button constructor 
the text you want on the button)
give the frame a size, in pixels
finally, make it visible!! (if you forget 
this step, you won’t see anything when 
you run this code)
add the button to the frame’s 
content pane
Let’s see what happens when we run it: 
%java SimpleGui1
make a frame and a button
this line makes the program quit as soon as you 
close the window (if you leave this out it will 
just sit there on the screen forever)


356
 
chapter 12
That’s not exactly true. When you press the button it shows that 
‘pressed’ or ‘pushed in’ look (which changes depending on the 
platform look and feel, but it always does something to show when 
it’s being pressed).
The real question is, “How do I get the button to do something 
specifi c when the user clicks it?” 
But nothing happens when I click it...
We need two things:

method 
to be called when the user 
clicks (the thing you want to happen as 
a result of the button click).

Download 40,57 Mb.

Do'stlaringiz bilan baham:
1   ...   325   326   327   328   329   330   331   332   ...   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