Java Learning Note _midi_gui

Source: Internet
Author: User

1 Importjavax.sound.midi.*;2 Importjavax.swing.*;3 Importjava.awt.event.*;4 Importjava.awt.*;5 6 classMypanel_2extendsJPanelImplementscontrollereventlistener{7     Booleanmsg =false;8     9      Public voidpaintcomponent (Graphics g) {Ten         if(msg) { OneG.fillrect (0, 0, This. GetWidth (), This. GetHeight ()); A             intRed = (int) (Math.random () * 255); -             intGreen = (int) (Math.random () * 255); -             intBlue = (int) (Math.random () * 255); theColor Randomcolor =NewColor (red, green, blue); - G.setcolor (randomcolor); -G.filloval (70, 40, 100, 100); -msg =false; +         } -     } +      A      Public voidControlchange (shortmessage event) { atmsg =true; - repaint (); -     } - } -  -  Public classmidi{ in      -JFrame frame =NewJFrame ("My first Music Video"); to mypanel_2 Panel;  +      -      Public voidShow_my_panel () { the frame.setdefaultcloseoperation (jframe.exit_on_close); *Panel =Newmypanel_2 (); $ Frame.setcontentpane (panel);Panax NotoginsengFrame.setbounds (30, 30, 300, 300); -Frame.setvisible (true); the     } +      A      Public StaticMidievent Makeevent (intCmdintChanintOneintBoth,inttick) { theMidievent event =NULL; +         Try { -Shortmessage A =Newshortmessage (); $ a.setmessage (Cmd, Chan, One, and both); $event =NewMidievent (A, tick); -}Catch(Exception e) {} -         returnevent; the     } -     Wuyi      Public voidPlay () { the         Try { -Sequencer player =midisystem.getsequencer (); Wu Player.open (); -              About             int[] Eventsiwant = {127}; $ Player.addcontrollereventlistener (panel, eventsiwant); -              -Sequence seq =NewSequence (SEQUENCE.PPQ, 4);//Divisiontype, resolution -              ATrack track =Seq.createtrack (); +              the              for(inti = 5; I < 61; i+= 4) { -Track.add (Makeevent (144, 1, I, 100, i)); $Track.add (Makeevent (176, 1, 127, 0, i)); theTrack.add (makeevent, 1, I, I, 2)); the             } the              the player.setsequence (seq); -PLAYER.SETTEMPOINBPM (220); in Player.start (); the              while(Player.isrunning ()) { theThread.Sleep (1000); About             } the player.close (); the              the}Catch(Exception ex) { + ex.printstacktrace (); -         } the     }    Bayi      the      Public Static voidMain (string[] args) { theMIDI MIDI =NewMidi (); -          - Midi.show_my_panel (); the Midi.play (); the     } the}

Java Learning Note _midi_gui

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.