— Scott McNealy, Sun Microsystems Chairman, President and ceo



Download 40,57 Mb.
Pdf ko'rish
bet420/555
Sana26.05.2022
Hajmi40,57 Mb.
#609235
1   ...   416   417   418   419   420   421   422   423   ...   555
Bog'liq
Head First Java (Kathy Sierra, Bert Bates) (z-lib.org)

System.out.println(line);
}
reader.close();
} catch(Exception ex) {
ex.printStackTrace();
}
}
}
Don’t forget the import.
Chain the FileReader to a 
BufferedReader for more 
efficient reading. It’ll go back 
to the file to read only when 
the buffer is empty (because the 
program has read everything in it).
A FileReader is a connection stream for 
characters, that connects to a text file 
Make a String variable to hold 
each line as the line is read
reading 
files
MyText.txt
This says, “Read a line of text, and assign it to the 
String variable ‘line’. While that variable is not null 
(because there WAS something to read) print out the 
line that was just read.”
Or another way of saying it, “While there are still lines 
to read, read them and print them.”


serialization 
and
file I/O
you are here
4
455
Quiz Card Player (code outline)
public class QuizCardPlayer {
public void go() {
// build and display gui
}
class NextCardListener implements ActionListener {
public void actionPerformed(ActionEvent ev) {
// if this is a question, show the answer, otherwise show next question
// set a flag for whether we’re viewing a question or answer
}
}
class OpenMenuListener implements ActionListener {
public void actionPerformed(ActionEvent ev) {
// bring up a file dialog box
// let the user navigate to and choose a card set to open
}
}
private void loadFile(File file) {
// must build an ArrayList of cards, by reading them from a text file
// called from the OpenMenuListener event handler, reads the file one line at a time
// and tells the makeCard() method to make a new card out of the line
// (one line in the file holds both the question and answer, separated by a “/”)

private void makeCard(String lineToParse) {
// called by the loadFile method, takes a line from the text file
// and parses into two pieces—question and answer—and creates a new QuizCard
// and adds it to the ArrayList called CardList

}



Download 40,57 Mb.

Do'stlaringiz bilan baham:
1   ...   416   417   418   419   420   421   422   423   ...   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