View this PageEdit this PageAttachments to this PageHistory of this PageHomeRecent ChangesSearch the SwikiHelp Guide

Lab 3-2a


Lab2a: Using JES

Lab 2, Part A: Using JES

Objectives:


Installing JES

If you have not done so already, you need to install JES on your computer.

For Windows Users:
  1. Insert the software CD.
  2. Double-click "My Computer" or open it from the "Start" menu.
  3. Open the CD drive (probably D:) by double-clicking it.
  4. Double-click to open the folder that is called "Win".
  5. Copy the folder called "JES" from inside the Win folder onto your C: drive.
  6. Open the new JES folder on your computer.
  7. To open JES, double-click on the snake icon titled "JES". It may take a minute for JES to get started.
If JES does not open:
  1. Launch JES by double-clicking on the icon called "jes-console.exe". It looks like a black box.
  2. Wait to see if JES opens. If JES opens, you're done! From now on, you'll need to open JES with this icon. But when JES is open, do not close the black console window.
  3. If JES still doesn't open with either method, contact your TA or post your problem to the CoWeb.

*Later in the course, we will be using QuickTime for Java to do video playback. You need to install that now.

Installing QuickTime for Java:
  1. Launch the program called “QuickTimeInstaller” in the QuickTimeInstaller directory of your CD by double-clicking it.
  2. Select “Custom Installation” on the install type window.
  3. On the Select Components window, check the box next to “QuickTime for Java”.
  4. Continue with the installation as directed.
For Mac OS X users:
  1. Insert the software CD and open it from your desktop.
  2. Open the folder called "Mac". Then click and drag the folder called "JES" into your home directory (the icon that looks like a house). This will copy the folder into your home directory.
  3. To open JES, open the terminal window by going through the menus Applications->Utilities->Terminal. Type in "CD JES". Press enter.
  4. Then type in "./JES &" and then enter. Once JES has opened, you can close the terminal window.

*Unfortunately, video playback will not work from within JES on Macintosh operating systems. All Mac systems do come with QuickTime, though. Almost every video format can be played using QuickTime.

All Users:
  1. After you have gotten JES installed, open the program (see specific directions above).
  2. A message appears about JES in a new window which you should read and then close. This message is only shown the first time you open JES.
  3. Then JES will open a window called "JES Settings". As instructed, type in your full name and your student number (gtXXXXX).
  4. Then click on the button that says Save Changes. This saves your settings. If you have made any mistakes, you can fix them at any time by going to the "Turnin" menu in JES and then selecting "Register".
  5. One valuable reference for the JES environment is the Help utility. Click on the "Help" menu and go to "Getting Started with JES". This will provide you with some beginning information about our programming environment. You will need to read it before you complete the lab.

Running a Recipe in JES

  1. Start up JES.
  2. Cut and paste the the jython code below into a new JES file.


  3. # Simplest Audio Example
    
    def example1():
      file = 'Elliot-hello.wav'
      sound = makeSound(file)
      play(sound)
    
    # Add example2() here:
    
    
    #Question 1:
    #Which operation system are you using? (Linux, Win95/98, WinNT, WinME, MacOSX, etc.)
    #
    #
    #Question 2:
    #Explain in English what is happening in each line of the recipe and 
    #what the words "def", "file", and "sound" mean in it. # #

  4. Now you must save and load the file. Click the Load button. A dialogue box will ask you if you would like to save. Click "ok," then save the file as "lab2a.py". The file will then automatically load.


  5. The file "Elliot-hello.wav" that we use in example1() is on the CD for this course, along with other sounds and images you will want to use in the future. To access these files easily, you need to copy them onto your computer from the disk like this:
    1. Insert the CD, and then open by clicking on it. Locate the folder labeled "mediasources".
    2. Click on the Mediasources folder to select it, and then copy it by selecting Edit->Copy (or by using the shortcut keys: control + C for Windows, apple + C for Mac).
    3. Now, locate the JES folder on your computer. It should be in your C: drive if you are a Windows user. For Mac users, it is in your home directory. Double-click on the folder to open it.
    4. Paste the mediasources folder into the JES directory by selecting Edit->Paste (or by using the shortcut: control + V for Windows, apple + V for Mac).

  6. Let's see what happens when we try to run the program called example1() as is.  In the command area, type in

            example1()

    and hit enter.

    Immediately, part of your code in the program area will be highlighted in yellow, and a square around your block will appear. In the command area, you will get an error message that looks something like this:

    There is no file at Elliot-hello.wav
    An error occurred attempting to pass an argument to a function.

    Looks like JES can't find the sound file.  Although we know that it is on our computer in our JES folder in the mediasources folder (because that is where we just put it), the computer does not. Remember: computers are pretty stupid, so we'll have to help it find the location of the sound file. We sent the computer a message to use the "Elliot-hello.wav" file, but we didn't tell the computer where it needed to look. 



  7. To make this recipe work, we need to know the entire path name of the file "Elliot-hello.wav". The path name of a file is like its address in the computer. Each part of the path name gives the computer a smaller, more defined place to look for that file. Every drive, directory, and folder must be noted in the correct order and format for the computer to locate the file. You'll be learning much more about this concept in lecture. For now, we'll give you the path name. However, different operating systems like their path names to look certain ways.  So, make sure you use the correct format:

        Mac and Unix: "/Users/<USER NAME>/JES/mediasources/Elliot-hello.wav"
    *In the space filled above with <USER NAME>, fill in the name of whomever you are logged in as. It is probably your name if you are working on your own computer.

       Windows: "C:\JES\mediasources\Elliot-hello.wav"
    *Windows users need to always place an "r" before any complete path name for a file when using JES. Your path entries in JES should always look like this: r"C:\***\*****\......"

    You also need to know that all file names in JES need to be surrounded by quotation marks. Your recipe should now look like this:

      def example1():
        file = "/Users/.../JES/mediasources/Elliot-hello.wav"
        sound = makeSound(file)
        play(sound)
    OR
      def example1()
        file = r"C:\JES\mediasources\Elliot-hello.wav"
        sound = makeSound(file)
        play(sound)

  8. Since we have made a change to our lab2a.py file, we need to load it into JES before trying to run example1() again. So click on the Load button, and then reply "ok" to the save prompt. Next, click in the command area. Type example1() at the prompt (>>>) and hit enter. You should now hear a male voice say, "Hello, world," as long as your speakers are on and functioning. You have just run a recipe in JES!

Writing a JES recipe

What if we wanted to play a different .wav file? We would have to change the recipe to include the entire path name of the new file and then load the new recipe. And we would have to do this every time we wanted to play a new sound. How annoying! Fortunately, there is an easier way to do this. There is a function called "pickAFile()" that will let you find the path to a file on your computer. This function allows you to play any .wav file on your computer using only one recipe; all you have to do is pick which one you want to hear when the computer prompts you.

Here is how you incorporate "pickAFile()" into our previous recipe. All you need to do is:

  1. Copy and paste example1() into the space below the line that says
    # Add example2() here:

  2. Change the name of the function to example2().

  3. Then replace '..\JES\mediasources\Elliot-hello.wav' in your new recipe with "pickAFile()". Your recipe will now look like this:
        def example2(): 
            file = pickAFile() 
            sound = makeSound(file) 
            play(sound) 
    

  4. Since we have made a change to our lab2a.py file, we need to load again to save the changes to the file.

  5. Next, you can type example2() at the prompt in the command area and hit enter. A File Browser window will appear, allowing you to choose which file you would like to play. To reach a file from "mediasources", however, you must first select which directory JES is in (Home directory for Mac, C: for Windows). Then you must select JES. Then you must select "mediasources". Finally, from there you can select a new .wav file or you can just use Elliot-hello.wav again.

Questions

Below your two recipes in the JES program area, add your answers to the questions that you copied and placed there. Each line of your written response needs to start with a # so JES doesn't attempt to run your answers. It should look something like:

# Question 1 
#    answer blah blah blah 
#    blah blah

# Question 2 
#    answer blah blah blah 
#    blah blah


Here are the questions again:

Question 1:
Which operating system are you using? (Windows 95, Windows 98, Windows ME, Windows NT, Windows 2000, Windows XP, Mac OS X, Linux, etc.)?

Question 2:
Refer to example1() to answer.

 
def example1(): 
    file = "Elliot-hello.wav" 
    sound = makeSound(file) 
    play(sound) 

Explain in English what is happening in each line of the recipe, and what the words "def", "file", and "sound" mean in it.


Turning in Your Lab

Your JES lab and your Microsoft Word lab need to be turned in together. Please complete the Word lab (here) before continuing the turnin.

The turning method is the same for labs, homeworks, and projects. In order to turn in assignments, your turnin settings must be set up correctly in JES. Hopefully, you did this when you first opened JES. If not, you can set them up by choosing "Settings" in the "Turnin" menu. See "Turning in Assignments" in the "Help" menu for more information.

To submit this lab, first make sure that your answers to the above questions and your two programs (example1() and example2()) are in the program area of the JES window. Be sure that you have loaded to save all of the changes you have made. Your computer must be connected to the Internet, as well.

  1. Go to the "Turnin" menu at the top of the JES Window.
  2. Select the "Assignment" option. This opens a new window in JES which should show your name, your GT#, and the name of the file that you want to submit, in this case lab2a.py.
  3. Select "LAB 2" from the "Assignment to Submit" pull-down menu.
  4. Click on the Add File button under the "Media Files Attached" box. This will give you a file browser window, where you will select the edited Word file that contains your solutions to the other section of this lab (lab2b). Make sure this file appears in the "Media Files Attached" box.
  5. If you collaborated with anyone else on this lab, state this fact and the person’s name in the "Notes to TA" box.
  6. Click on the Turnin button at the very bottom of the window to submit your lab.
NOTE:
If you want to turn in a second version of an assignment, you can do so through JES as long as you do so before the assignment is due. For example, if you turn in an assignment two days before it is due, and then find a mistake and correct it, you can still turn in the corrected version as long as you do within two days. However, your TA will only grade your last submission! A new submission will always overwrite the previous submission. Also, JES will not prevent you from turning in assignments after they are due; however, they will not be accepted. You are responsible for turning in assignments before they are due.

Link to this Page