O'Reilly logo

Killer Game Programming in Java by Andrew Davison

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required