— Scott McNealy, Sun Microsystems Chairman, President and ceo


participant sends one to the server



Download 40,57 Mb.
Pdf ko'rish
bet428/555
Sana26.05.2022
Hajmi40,57 Mb.
#609235
1   ...   424   425   426   427   428   429   430   431   ...   555
Bog'liq
Head First Java (Kathy Sierra, Bert Bates) (z-lib.org)


participant sends one to the server.
Serializing a pattern
Saving a BeatBox pattern
public class MySendListener implements ActionListener {
public void actionPerformed(ActionEvent a) {
boolean[] checkboxState = new boolean[256];
for (int i = 0; i < 256; i++) {
JCheckBox check = (JCheckBox) checkboxList.get(i);
if (check.isSelected()) {
checkboxState[i] = true;
}
}
try {
FileOutputStream fileStream = new FileOutputStream(new File(“Checkbox.ser”));
ObjectOutputStream os = new ObjectOutputStream(fileStream);
os.writeObject(checkboxState);
} catch(Exception ex) {
ex.printStackTrace();
}

// close method

// close inner class
It all happens when the user clicks the 
button and the ActionEvent fires.
This is an inner class inside 
the BeatBox code.
Make a boolean array to hold the 
state of each checkbox.
Walk through the checkboxList 
(ArrayList of checkboxes), and 
get the state of each one, and 
add it to the boolean array.
This part’s a piece of cake. Just 
write/serialize the one boolean array!


464
 
chapter 14
This is pretty much the save in reverse... read the boolean array and use it 
to restore the state of the GUI checkboxes. It all happens when the user hits 
the “restore” ‘button.
Restoring a pattern
Restoring a BeatBox pattern
public class MyReadInListener implements ActionListener {
public void actionPerformed(ActionEvent a) {
boolean[] checkboxState = null;
try {
FileInputStream fileIn = new FileInputStream(new File(“Checkbox.ser”));

Download 40,57 Mb.

Do'stlaringiz bilan baham:
1   ...   424   425   426   427   428   429   430   431   ...   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