/** Example panel. Animate an example file (E short) and play a tone (D long). */
  public static void main(String[] args) {
    try {
      JFrame f = new JFrame(AnimationPanel.class.getName());
      f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      AnimationRenderer ani = new AnimationRenderer();

      final AnimationPanel view = new AnimationPanel(ani);

      f.getContentPane().add(view, BorderLayout.CENTER);
      f.pack();
      f.setLocationRelativeTo(null);
      f.setVisible(true);

      File file = new File("datafiles/examples/vis/es_.txt");

      final AnimationSequence animation = AnimationParser.parseFile(file);

      String filename =
          NotesEnum.D.toString().toLowerCase() + "_" + DurationEnum.LONG.codeString() + ".wav";
      // System.out.printf("sound clip filename = %s\n", filename);

      File dir = new File("datafiles/examples/aud");

      final Playable audio = SoundClip.findPlayable(filename, dir, false);

      Runnable r =
          new Runnable() {
            @Override
            public void run() {
              audio.play();
            }
          };

      long currentTime = System.nanoTime();
      ani.setAnimationSource(
          new AnimationSource() {
            public AnimationSequence getAnimationSequence() {
              return animation;
            }

            public int getNumPoints() {
              return 5;
            }

            public float getDiskRadius() {
              return 0.3f;
            }

            public boolean isConnected() {
              return true;
            }
          });

      ani.setNanoStartTime(currentTime);
      SwingUtilities.invokeLater(r);
    } catch (Throwable ex) {
      ex.printStackTrace();
    }
  }
Ejemplo n.º 2
0
 public void propertyChange(PropertyChangeEvent evt) {
   if (DisplayOptions.isUpdateUIEvent(evt)) {
     SwingUtilities.updateComponentTreeUI(this);
     gradientPanel.remove(drawable);
     JPanel newpanel = createGradientPanel();
     contentPane.remove(gradientPanel);
     gradientPanel = newpanel;
     gradientPanel.add(drawable, BorderLayout.CENTER);
     contentPane.add(gradientPanel, BorderLayout.CENTER);
   }
 }