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

Media Computation Java FAQ

How do I prompt the user for input or do output?

There are two simple classes for input and output. You can use SimpleInput to ask the user to enter
information.

double totalBill = SimpleInput.getNumber("Enter the bill total");
int numPeople = SimpleInput.getIntNumber("How many people are paying?");
int numGuess = SimpleInput.getIntNumber("Guess a number from 1 to 100", 1, 100);
String name = SimpleInput.getString("What is your name?");

You can use SimpleOutput to show a warning, error, or information.
SimpleOutput.showWarning("Watch out for falling rocks!");
SimpleOutput.showError("The filename you entered doesn't exist");
SimpleOutput.showInformation("The cost per person is $6.50");

I can't write out a picture or sound to the mediasources directory

When you copy the directory from the CD the default is for it to be write protected (read only). You
can change this by right clicking on the directory name and then select Properties. Uncheck the Read-only
box.


I get an error when I try to set the media path with FileChooser.setMediaPath("directory name")

The version of FileChooser on the CD tries to save a file in the current directory. With DrJava this is the directory
that DrJava is in. If you don't have write permission this will give you an error. You can use this version instead which writes the file to the directory FileChooser is in. Put these in your bookClasses directory.
FileChooser.java
FileChooser.class


DrJava doubles the directory name when I add classpaths

Don't open the directory that you want to add by double clicking on it but just single click on it to select it and then click on the Select button. For example, if you want to add c:/intro-prog-java/bookClasses/ double click on c to open it and then double click on intro-prog-java to open it and then single click on bookClasses to select it and click the Select button. This problem is solved in the more recent version of DrJava.
Uploaded Image: selectBookClasses.gif

DrJava doesn't use the new classpath I added

Close DrJava and start it again.


DrJava can't find tools.jar

If you have more than one version of Java installed on your machine DrJava has trouble. But, all you need to do
is select the directory with tools.jar one time and it will save the location of it. So if you want to use Java 1.5 (5.0) select c:/Program Files/Java/jdk1.5.0_XX/lib/tools.jar (where XX matches the number of the minor version). If you only find jre1.5 directories in c:/Program Files/Java then you only have the Java runtime and not the development environment. You will need to install the development environment either from the CD or from http://java.sun.com/javase/downloads/index.jsp

Can I use your classes with Eclipse?

Yes.

Create a project using from existing source and pick bookClasses.
newProject.jpg

The javazoom classes must be in a jar file. The jar is here:
javazoom.jar. Then just add javazoom.jar to the
list of external libraries. Go to Project -> Properties and click on Java Build Path on the left. Click on the Add External
Jars button and add javazoom.jar.



If you are using the movie capture you also need to add jmf.jar and sound.jar to the Java Build Path as shown below.
eclipseSEtUp.jpg.
These are jar files that come with the Java Media Framework.

Links to this Page