— Scott McNealy, Sun Microsystems Chairman, President and ceo



Download 40,57 Mb.
Pdf ko'rish
bet388/555
Sana26.05.2022
Hajmi40,57 Mb.
#609235
1   ...   384   385   386   387   388   389   390   391   ...   555
Bog'liq
Head First Java (Kathy Sierra, Bert Bates) (z-lib.org)

418
 
chapter 13
Code Kitchen
This part’s optional. We’re making the full BeatBox, GUI 
and all. In the Saving Objects chapter, we’ll learn how to 
save and restore drum patterns. Finally, in the networking 
chapter (Make a Connection), we’ll turn the BeatBox into a 
working chat client.
Code 
Kitchen


using 
swing
you are here
4
419
This is the full code listing for this version of the BeatBox, with buttons for starting, 
stopping, and changing the tempo. The code listing is complete, and fully-
annotated, but here’s the overview:
Making the BeatBox
1
2
3
4
Build a GUI that has 256 checkboxes (JCheckBox) that start out 
unchecked, 16 labels (JLabel) for the instrument names, and four 
buttons.
Register an ActionListener for each of the four buttons. We don’t 
need listeners for the individual checkboxes, because we aren’t 
trying to change the pattern sound dynamically (i.e. as soon as the 
user checks a box). Instead, we wait until the user hits the ‘start’ 
button, and then walk through all 256 checkboxes to get their state 
and make a MIDI track.
Set-up the MIDI system (you’ve done this before) including getting 
a Sequencer, making a Sequence, and creating a track. We are using 
a sequencer method that’s new to Java 5.0, setLoopCount( ). This 
method allows you to specify how many times you want a sequence 
to loop. We’re also using the sequence’s tempo factor to adjust the 
tempo up or down, and maintain the new tempo from one iteration of 
the loop to the next.
When the user hits ‘start’, the real action begins. The event-handling 
method for the ‘start’ button calls the buildTrackAndStart() method. 
In that method, we walk through all 256 checkboxes (one row at 
a time, a single instrument across all 16 beats) to get their state, 
then use the information to build a MIDI track (using the handy 
makeEvent() method we used in the previous chapter). Once the track 
is built, we start the sequencer, which keeps playing (because we’re 
looping it) until the user hits ‘stop’.



Download 40,57 Mb.

Do'stlaringiz bilan baham:
1   ...   384   385   386   387   388   389   390   391   ...   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