Đang chuẩn bị liên kết để tải về tài liệu:
head first java second edition phần 7

Đang chuẩn bị nút TẢI XUỐNG, xin hãy chờ

Bây giờ bạn đã nhìn thấy rằng I / O inJava thực sự là khá đơn giản, đặc biệt là nếu bạn dính vào các kết nối / chuỗi kết hợp phổ biến nhất. Nhưng có một vấn đề bạn thực sự có thể quan tâm đến. (không phải thoáng qua) đã thay đổi từ một đôi một String. Đó là sự nhạy cảm an toàn của loại violatesJava trong một cách lớn. | controller events Version Two registering and getting ControllerEvents _ rzed Ù implerMrrrt the lister âỏe import javax. sound.midi . public class MiniMualePlayer2 implements ControllerEvantLlstener public static void main String args MinlMusicPlayer2 mini new MinlMuslcPlayor2 0 mini.go 0 public void go try Sequencer sequencer MidiSystem.getSequancer0 sequencer.open int evantsIWant 127 . r Í sequencer.addControllorEventLlstanar this events IWant Sequence seq new Sequence Sequence.PPQ 4 Track track seq.creataTrack0 for int i 5 1 60 i 4 track.add makaEvent 144 1 1 100 i track.add makaEvent 176 1 127 0 1 1 track.add makeEvant 128 1 i 100 1 2 end loop piỏk up -th k jl_. type is I event number 27 Th .71 ìịỉ put i L JuS Srtt a K Hayed sequencer.setsequence seq sequencer.setTempoInBPM 220 sequencer.start catch Exception ax ax.printstackTraca0 close public void controlchange ShortMessage event System.out.printin la public MidiEvent makaEvant int comd int chan int one int two int tick MidiEvent event null try ShortMassage a new ShortMessage0 a.setMessage comd chan one two event new MidlEvent a tick Code that s different from the previous J catch Exception e version is highlighted in gray and we re return event not running it oil within main this time II close class 390 chapter 12 getting gui Version Three drawing graphics ỉn time with the music This final version builds on version two by adding the GUI parts. We build a frame add a drawing panel to it and each time we get an event we draw a new rectangle and repaint the screen. The only other change from version two is that the notes play randomly as opposed to simply moving up the scale. The most important change to the code besides building a simple GUI is that we make the drawing panel implement the ControllerEventListener rather than the program itself. So when the drawing panel an inner class gets the event it knows how to take care of itself by drawing the rectangle. Complete code for this version is on the next page.