Testing the Loaders

The constructor for LoadersTests creates the images canvas (a SoundsPanel object) and the rest of the GUI, and it initializes the loaders:

    // the clip and midi sound information files, located in Sounds/
    private final static String SNDS_FILE = "clipsInfo.txt";
    private final static String MIDIS_FILE = "midisInfo.txt";

    // global variables
    private ClipsLoader clipsLoader;
    private MidisLoader midisLoader;

    public LoadersTests()
    { super( "Sounds Tests" );
      Container c = getContentPane();
      c.setLayout( new BorderLayout() );

      SoundsPanel sp = new SoundsPanel(this);   // the images canvas
      c.add( sp, BorderLayout.CENTER);
      initGUI(c);                        // the rest of the controls

      // initialise the loaders
      clipsLoader = new ClipsLoader(SNDS_FILE);
      clipsLoader.setWatcher("dog", this);     // watch the dog clip

      midisLoader = new MidisLoader(MIDIS_FILE);
      midisLoader.setWatcher(this);        // watch the midi sequence

      addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent ev) {
          midisLoader.close();   // shut down the sequencer
          System.exit(0);
        }
      });
   

      pack();
      setResizable(false);  // fixed size display
      centerFrame();        // placed in the center of the screen
      setVisible(true);
    }

Watching the Loaders

As part of the loaders setup, setWatcher() is called in the ClipsLoader and MidisLoader objects:

    clipsLoader.setWatcher("dog", this);    // watch the dog clip

    midisLoader.setWatcher(this);           // watch midi playing

A call to setWatcher() tells the loader that this object (LoadersTest) should be notified whenever ...

Get Killer Game Programming in Java now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.