JMSL Tutorial: MusicJob

We want to make the PrintingJob more flexible, so it can print any message at all. We also want to be able to redirect its text output whereever we want.

To customize the message to be printed by our MusicJob, we'll give it a private class member of type String, and a constructor to automatically set this String to the message we want it to print.

To redirect its output, we use JMSL.out.println() which defaults to System.out. We'll see how to redirect this a little later.

The essential code excerpts are shown below:
 

...
private String msg;
/* Constructor, automatically initializes message */
PrintingJob(String s) {
        super();
        msg = s;
}

...
 public double repeat(double playTime)   {
        JMSL.out.println(msg);
        return playTime;
 }
JMSL.out defaults to System.out. For now, let's finish the task by adding a main method to actually launch the job, so this can run as a stand-alone application.   To test this class compile it with javac, then run it with java. Here's the complete source for our PrintingJob class.

We'll implement this class in an applet next, so you can see it in action.
 
 
Previous Tutorial Index Tutorial Contents Next

  (C) 1997 Phil Burk and Nick Didkovsky, All Rights Reserved
  JMSL is based upon HMSL (C) Phil Burk, Larry Polansky and David Rosenboom.