package tutor; import java.net.*; import java.io.*; import java.util.*; import java.applet.*; /** * * This class allows a student to practice learning a language * by listening to the sounds and then looking at the * transcription and the {@linkplain tutor.Translation} * * @see: DataFile, SoundDownload, Record etc */ public class Practice extends Object { //-------------------------------------------- /** the current user language */ private String userLanguageCode; //-------------------------------------------- public static String NEWLINE = System.getProperty("line.separator"); //-------------------------------------------- //-------------------------------------------- public static void main(String[] args) throws Exception { StringBuffer sbUserMessage = new StringBuffer(""); sbUserMessage.append("usage: java Practice [datafile] \n"); sbUserMessage.append("An example of a datafile can be seen at \n"); sbUserMessage.append("http://bumble.sourceforge.net/ \n"); if (args.length == 0) { System.out.println(sbUserMessage); System.exit(-1); } StringBuffer sOutput = new StringBuffer(); RecordSet dfTest; dfTest = new RecordSet(args[0]); try { File fDataFile = new File(args[0]); dfTest = new RecordSet(args[0]); } catch (Exception e) { sOutput.append("There was a problem with the [datafile] argument you passed"); sOutput.append(args[0]); sOutput.append("The error message generated was"); sOutput.append(e); sOutput.append(sbUserMessage); sOutput.append(""); System.exit(-1); } SoundDownload sdCurrent = new SoundDownload(); SoundLoadManager dmTest = new SoundLoadManager(dfTest); Vector soundDownloads = new Vector(); Enumeration ee = soundDownloads.elements(); dmTest.startDownloading(); //-------------------------------------- //-- make a simple command loop BufferedReader brUserInput = new BufferedReader( new InputStreamReader(System.in)); String sCommand = "h"; sbUserMessage.setLength(0); String sHelpMessage = new String( "Commands; \n" + " p - play the current sound \n" + " n - play the next sound \n" + " s - show download information for the current sound \n" + " d - show the data record \n" + " a - show information for all sounds downloaded \n" + " l - \n" + " q - quit \n" + " h - help, show this message \n"); //---------------------------------- //-- the command loop //-- while (!sCommand.equals("q")) { //-------------------------------- if (sCommand.equals("p") || sCommand.equals("")) { sdCurrent.getSoundObject().play(); } //-------------------------------- if (sCommand.equals("n")) { if (!ee.hasMoreElements()) { ee = soundDownloads.elements(); } sdCurrent = (SoundDownload)ee.nextElement(); sdCurrent.getSoundObject().play(); } //-------------------------------- if (sCommand.equals("s")) { System.out.println(sdCurrent); } //-------------------------------- if (sCommand.equals("d")) { System.out.println(sdCurrent.getRecord()); } //-------------------------------- if (sCommand.equals("l")) { soundDownloads = dmTest.getGoodDownloads(); System.out.println("loaded=" + soundDownloads.size()); ee = soundDownloads.elements(); sdCurrent = (SoundDownload)ee.nextElement(); } //-------------------------------- // if (sCommand.equals("s")) { System.out.println(dmTest.printStatistics()); } //-------------------------------- if (sCommand.equals("help") || sCommand.equals("h")) { System.out.println(sHelpMessage); } System.out.print(">"); sCommand = brUserInput.readLine(); } //-- while System.out.println(dmTest.printStatistics()); System.out.println(dmTest.toString()); } //-- main() } //-- Practice class