— Scott McNealy, Sun Microsystems Chairman, President and ceo



Download 40,57 Mb.
Pdf ko'rish
bet12/555
Sana26.05.2022
Hajmi40,57 Mb.
#609235
1   ...   8   9   10   11   12   13   14   15   ...   555
Bog'liq
Head First Java (Kathy Sierra, Bert Bates) (z-lib.org)

xvi
 
13
Work on your Swing
Swing is easy. 
Unless you actually care where everything goes. Swing code looks 
easy, but then compile it, run it, look at it and think, “hey, that’s not supposed to go there.”
The thing that makes it easy to code is the thing that makes it hard to control—the 
Layout 
Manager
. But with a little work, you can get layout managers to submit to your will. In 
this chapter, we’ll work on our Swing and learn more about widgets. 
14
Saving Objects
Objects can be flattened and inflated. 
Objects have state and behavior. 
Behavior lives in the class, but state lives within each individual object. If your program 
needs to save state, you can do it the hard way, interrogating each object, painstakingly 
writing the value of each instance variable. Or, you can do it the easy OO way—you simply 
freeze-dry the object (serialize it) and reconstitute (deserialize) it to get it back.
Components in 
the east and 
west get their 
preferred width.
Things in the 
north and 
south get their 
preferred height.
The center gets 
whatever’s left.
Swing Components 
400
Layout Managers (they control size and placement) 
401
Three Layout Managers (border, flow, box) 
403
BorderLayout (cares about five regions) 
404
FlowLayout (cares about the order and preferred size) 
408
BoxLayout (like flow, but can stack components vertically) 
411
JTextField (for single-line user input) 
413
JTextArea (for multi-line, scrolling text) 
414
JCheckBox (is it selected?) 
416
JList (a scrollable, selectable list) 
417
Code Kitchen (The Big One - building the BeatBox chat client) 
418
Exercises and puzzles 
424
Saving object state 
431
Writing a serialized object to a file 
432
Java input and output streams (connections and chains) 
433
Object serialization 
434
Implementing the Serializable interface 
437
Using transient variables 
439
Deserializing an object 
441
Writing to a text file 
447
java.io.File 
452
Reading from a text file 
454
Splitting a String into tokens with split() 
458
CodeKitchen 
462
Exercises and puzzles 
466
serialized
deserialized
Any questions
?



Download 40,57 Mb.

Do'stlaringiz bilan baham:
1   ...   8   9   10   11   12   13   14   15   ...   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