Java: Malen von zufälligen Formen auf JFrame gegen gespielte Musik

ich bintrying to paint JFrame when music is played Werden diese Formen nach dem Zufallsprinzip ohne Berechnung erstellt und wenn eine vorhanden istsome music played there pops up a JFrame and these shapes are painted there, Das Problem ist, dass wenn ich diesen Code starte, kein musikalischer Sound und keine Formen gezeichnet werden, sondern nur ein Frame auftaucht und sonst nichts. Bitte überprüfe diesen Code und hilf mir, ihn zu korrigieren.

public class MusicBeatsDrawing {

    static JFrame frame; 
    DrawPanel dp =new DrawPanel();
    public static void main(String[] args)
    {
        MusicBeatsDrawing mbd= new MusicBeatsDrawing();
        mbd.go();

    }
    public void SetGui(){

        frame= new JFrame("Simple frame ; ");
        frame.setBounds(100, 100, 200, 200); 
        frame.setContentPane(dp);
        frame.setVisible(true);

    }

    public void go()
    {
        SetGui();
        try
        {
            Sequencer sequencer =  MidiSystem.getSequencer();
            sequencer.open(); 

            Sequence seq= new Sequence(Sequence.PPQ, 4);
            sequencer.addControllerEventListener(dp,new int [] {127});
            Track track =  seq.createTrack(); 
            int r  =  0; 
            for  (int  i  =  0; i  <  60 ; i+=  4) {

                r =  (int) Math.random()*50; 
                track.add(MakeEvent(144,1,r,100,i)); 
                track.add(MakeEvent(176,1,127,0,i)); 
                track.add(MakeEvent(128,1,r,100,i ));
            }
            sequencer.setSequence(seq);
            sequencer.start();
        }

        catch(Exception e)
        {e.printStackTrace(); }
    }

    public  MidiEvent  MakeEvent(int one , int two , int three , int four , int tick)
    {   
        MidiEvent event= null;
        try 
        {    
            ShortMessage sm= new ShortMessage();
            sm.setMessage(one,two, three, four);
            event= new MidiEvent(sm , tick );


        } catch (InvalidMidiDataException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return  event;   
    }
    class DrawPanel extends  JPanel implements ControllerEventListener
    {       
        boolean msg= false ; 


        public void paintComponent(Graphics g)
        {
            if(msg){ Graphics2D g2d= (Graphics2D) g; 

            int red= (int) (Math.random()*255); 
            int green= (int) (Math.random()*255) ;
            int blue= (int) (Math.random()*255); 

            g.setColor(new Color(red, green , blue));

            int height= (int)Math.random()*255;
            int width= (int)Math.random()*255;
            int x= (int)Math.random()*255;
            int y= (int)Math.random()*255;
            g.fillRect(height, width, x, y);        
            msg = false; 
            }
        }
        @Override
        public void controlChange(ShortMessage event) {
            msg= true; 
            repaint();          
        }}


}

Antworten auf die Frage(1)

Ihre Antwort auf die Frage