在哪里关闭课程? Java的

时间:2015-06-30 10:13:22

标签: java

我在这里编写了这个小程序,但我不知道在哪里关闭MiniMusicPlayer3类的大括号,有什么想法? 我已经复制了这段代码,这就是为什么我不知道在哪里关闭它,但如果我在真正结束时关闭它而不是1错误我得到13个错误.. xD

    public class MiniMusicPlayer3 {

以上是我需要关闭的代码部分。

import j.avax.sound.midi.*;
import java.io.*;
import javax.swing.*;
import java.awt.*;


public class MiniMusicPlayer3 {

static JFrame f = new JFrame("My First Music Video");
static MyDrawPanel ml;
public static void main(String[] args) {
    MiniMusicPlayer3 mini = new MiniMusicPlayer3();
    mini.go();

} //close methoda


public void setUpGui() {
    ml = new MyDrawPanel();
    f.setContentPane(ml);
    f.setBounds(30, 30, 300, 300);
    f.setVisible(true);
} //close methode


public void go() {
    setUpGui();

    try {
        Sequencer sequencer = MidiSystem.getSequencer();
        sequencer.open();
        sequencer.addControllerEventListener(ml, new int[] {
            127
        });
        Sequence seq = new Sequence(Sequence.PPQ, 4);
        Track track = seq.createTrack();

        int r = 0;
        for (int i = 0; i < 60; i += 4) {

            r = (int)(Math.random() * 50) + 1;
            track.add(makeEvent(144, 1, r, 100, i));
            track.add(makeEvent(176, 1, 127, 0, i));
            track.add(makeEvent(128, 1, r, 100, i + 2));

        } //end loop


        sequencer.setSequence(seq);
        sequencer.start();
        sequencer.setTempoInBPM(120);
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}

1 个答案:

答案 0 :(得分:0)

import javax.sound.midi.*;
import javax.swing.*;
import javax.sound.midi.MidiSystem;
import javax.sound.midi.Sequence;
import javax.sound.midi.Sequencer;


public class MiniMusicPlayer3 {

static JFrame f = new JFrame("My First Music Video");
static MyDrawPanel ml;
public static void main(String[] args) {
 MiniMusicPlayer3 mini = new MiniMusicPlayer3();
 mini.go();

} //close methoda


public void setUpGui() {
 ml = new MyDrawPanel();
 f.setContentPane(ml);
 f.setBounds(30, 30, 300, 300);
 f.setVisible(true);
} //close methode


public void go() {
 setUpGui();

 try {
    Sequencer sequencer = MidiSystem.getSequencer();
    sequencer.open();
    sequencer.addControllerEventListener(ml, new int[] {
        127
    });
    Sequence seq = new Sequence(Sequence.PPQ, 4);
    javax.sound.midi.Track track = seq.createTrack();

    int r = 0;
    for (int i = 0; i < 60; i += 4) {

        r = (int)(Math.random() * 50) + 1;
        track.add(makeEvent(144, 1, r, 100, i));
        track.add(makeEvent(176, 1, 127, 0, i));
        track.add(makeEvent(128, 1, r, 100, i + 2));

    } //end loop


    sequencer.setSequence(seq);
    sequencer.start();
    sequencer.setTempoInBPM(120);
 } catch (Exception ex) {
    ex.printStackTrace();
 }
 }
}//this was the last curly you need to put at the end of your code