public JPanel getGuiPanel() {

    JPanel mainPanel = new JPanel();
    myPanel = new MyDrawPanel();
    JButton playItButton = new JButton("Play it");
    playItButton.addActionListener(new PlayItListener());
    mainPanel.add(myPanel);
    mainPanel.add(playItButton);
    return mainPanel;
  }
  public ScaleMainFrame() {
    super(new BorderLayout());

    nameTF = new JTextField();
    JPanel top = new JPanel(new BorderLayout());
    top.add(new JLabel("Scale Name:"), BorderLayout.WEST);
    top.add(nameTF, BorderLayout.CENTER);

    PlayButton pb = new PlayButton("PLAY");
    tempoP = new IntSetPanel(1, 10000, "Tempo");
    tempoP.setValue(120);
    JPanel botL = new JPanel(new BorderLayout());
    botL.add(pb, BorderLayout.EAST);
    botL.add(tempoP, BorderLayout.CENTER);
    PianoKeyB kb = new PianoKeyB();
    kb.setPreferredSize(new Dimension(150, 40));
    // JPanel botTop = new JPanel(new GridLayout(1, 2));
    JPanel botTop = new JPanel(new FlowLayout());
    botTop.add(botL);
    botTop.add(kb);

    JButton newB = new JButton("New");
    saveB = new JButton("Save");
    JButton loadB = new JButton("Load");
    newB.addActionListener(this);
    saveB.addActionListener(this);
    loadB.addActionListener(this);
    pb.addActionListener(this);
    JPanel botBot = new JPanel(new GridLayout(1, 3));
    botBot.add(newB);
    botBot.add(saveB);
    botBot.add(loadB);
    JPanel bottom = new JPanel(new BorderLayout());
    bottom.add(botTop, BorderLayout.CENTER);
    bottom.add(botBot, BorderLayout.SOUTH);

    sp = new ScalePanel(this, kb);

    add(top, BorderLayout.NORTH);
    add(sp, BorderLayout.CENTER);
    add(bottom, BorderLayout.SOUTH);
    setPreferredSize(new Dimension(500, 300));

    fileChooser = new JFileChooser(new File("Features/Scales"));
    filter = new ScaleFilter();
    fileChooser.addChoosableFileFilter(filter);
    fileChooser.setFileFilter(filter);
  }
Пример #3
0
  public void buildGUI() {
    theFrame = new JFrame("Cyber BeatBox");
    theFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    BorderLayout layout = new BorderLayout();
    JPanel background = new JPanel(layout);
    background.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));

    checkboxList = new ArrayList<JCheckBox>();
    Box buttonBox = new Box(BoxLayout.Y_AXIS);

    JButton start = new JButton("Start");
    start.addActionListener(new MyStartListener());
    buttonBox.add(start);

    JButton stop = new JButton("Stop");
    stop.addActionListener(new MyStopListener());
    buttonBox.add(stop);

    JButton upTempo = new JButton("Tempo Up");
    upTempo.addActionListener(new MyUpTempoListener());
    buttonBox.add(upTempo);

    JButton downTempo = new JButton("Tempo Down");
    downTempo.addActionListener(new MyDownTempoListener());
    buttonBox.add(downTempo);

    Box nameBox = new Box(BoxLayout.Y_AXIS);
    for (int i = 0; i < 16; i++) {
      nameBox.add(new Label(instrumentNames[i]));
    }

    background.add(BorderLayout.EAST, buttonBox);
    background.add(BorderLayout.WEST, nameBox);

    theFrame.getContentPane().add(background);

    GridLayout grid = new GridLayout(16, 16);
    grid.setVgap(1);
    grid.setHgap(2);
    mainPanel = new JPanel(grid);
    background.add(BorderLayout.CENTER, mainPanel);

    for (int i = 0; i < 256; i++) {
      JCheckBox c = new JCheckBox();
      c.setSelected(false);
      checkboxList.add(c);
      mainPanel.add(c);
    } // end loop

    setUpMidi();

    theFrame.setBounds(50, 50, 300, 300);
    theFrame.pack();
    theFrame.setVisible(true);
  } // close method
  public void actionPerformed(ActionEvent e) {
    JButton b = (JButton) e.getSource();
    if (b.getText() == "PLAY") {
      if (scoreP != null) scoreP.playScale(sp.getScale(), tempoP.getValue());
    } else if (b.getText() == "New") {
      try {
        saveUnsaved();
      } catch (SaveAbortedException ex) {
        return;
      }

      sp.notes.removeAllElements();
      sp.repaint();
      nameTF.setText("");
      loadedFile = null;
    } else if (b.getText() == "Save") {
      if (nameTF.getText().equals("")) {
        JOptionPane.showMessageDialog(
            this,
            new JLabel("Please type in the Scale Name"),
            "Warning",
            JOptionPane.WARNING_MESSAGE);
        return;
      }
      fileChooser.setFileFilter(filter);
      int option = fileChooser.showSaveDialog(this);
      if (option == JFileChooser.APPROVE_OPTION) {
        File target = fileChooser.getSelectedFile();
        if (target.getName().indexOf(".scl") == -1) target = new File(target.getPath() + ".scl");
        try {
          PrintStream stream = new PrintStream(new FileOutputStream(target), true);
          save(stream);
          stream.close();
        } catch (Exception ex) {
          JOptionPane.showMessageDialog(
              this, new JLabel("Error: " + ex.getMessage()), "Error", JOptionPane.ERROR_MESSAGE);
        }
      }
    } else if (b.getText() == "Load") {
      try {
        saveUnsaved();
      } catch (SaveAbortedException ex) {
        return;
      }

      fileChooser.setFileFilter(filter);
      int option = fileChooser.showOpenDialog(this);
      if (option == JFileChooser.APPROVE_OPTION) {
        loadedFile = fileChooser.getSelectedFile();
        SAXParserFactory factory = SAXParserFactory.newInstance();
        ScaleParser handler = new ScaleParser(false);
        try {
          SAXParser parser = factory.newSAXParser();
          parser.parse(loadedFile, handler);
          // System.out.println("success");
        } catch (Exception ex) {
          // System.out.println("no!!!!!! exception: "+e);
          // System.out.println(ex.getMessage());
          ex.printStackTrace();
        }
        // -----now :P:P---------------
        System.out.println("name: " + handler.getName());
        nameTF.setText(handler.getName());
        sp.notes.removeAllElements();
        int[] scale = handler.getScale();
        for (int i = 0; i < scale.length; i++) {
          sp.addNote(scale[i]);
        }
        sp.repaint();
      } else loadedFile = null;
    }
  }
      public ParameterConfigurationPanel(String name, SensorType type) {
        this.type = type;
        this.name = name;
        setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));

        add(new Label(name));
        typeList = new JComboBox(controlTypes);
        typeList.addActionListener(
            new AbstractAction() {
              public void actionPerformed(ActionEvent e) {
                setType((String) typeList.getSelectedItem());
                configure();
              }
            });
        add(typeList);

        add(new Label("channel"));
        channel = new JSpinner(new SpinnerNumberModel(1, 1, 16, 1));
        channel.setValue(1);
        channel.addChangeListener(
            new ChangeListener() {
              public void stateChanged(ChangeEvent e) {
                configure();
              }
            });
        add(channel);

        add(new Label("cc"));
        cc = new JSpinner(new SpinnerNumberModel(21, 1, 127, 1));
        cc.setValue(21);
        cc.addChangeListener(
            new ChangeListener() {
              public void stateChanged(ChangeEvent e) {
                configure();
              }
            });
        add(cc);

        add(new Label("min"));
        min = new JSpinner();
        min.addChangeListener(
            new ChangeListener() {
              public void stateChanged(ChangeEvent e) {
                configure();
              }
            });
        add(min);

        add(new Label("max"));
        max = new JSpinner();
        max.setValue(127);
        max.addChangeListener(
            new ChangeListener() {
              public void stateChanged(ChangeEvent e) {
                configure();
              }
            });
        add(max);

        JButton button = new JButton("invert");
        button.addActionListener(
            new AbstractAction() {
              public void actionPerformed(ActionEvent e) {
                int saved = (Integer) min.getValue();
                min.setValue(max.getValue());
                max.setValue(saved);
              }
            });
        add(button);

        modeList = new JComboBox(eventhandler.getModeNames());
        modeList.addActionListener(
            new AbstractAction() {
              public void actionPerformed(ActionEvent e) {
                configure();
              }
            });
        add(modeList);
      }