//morse.java //ab //output a textfile as morse code //inputs from file // need to add datatransfer, speed adjust, pitch adjust? // different length dit and dah files import java.applet.Applet; import java.util.*; import java.awt.*; import java.io.*; import java.net.*; public class morse extends Applet implements Runnable { int wpm=15;//not yet used URL dit,dah; static String[] codedata={"a.-","b-...","c-.-.","d-..","e.","f..-.", "g--.","h....","i..","j.---","k-.-","l.-..","m--","n-.","o---","p.--.", "q--.-","r.-.","s...","t-","u..-","v...-","w.--","x-..-","y-.--", "z--..","0-----","1.----","2..---","3...--","4....-","5.....", "6-....","7--...","8---..","9----.", ",--..--","+.-.-.","*...-.-","/-..-.","=","?..--..","..-.-.-", " ","\n ","\r ","\t "};//etc static Hashtable codehash=new Hashtable(); {for (int i=0;i=0){ try {c=f.read();} catch (IOException e) { System.out.println("Read error. :"+(char)c+" "); c=-2; break;} // System.out.print((char)c+" "+c+","); if (c=='<') { //skip blocks of <> *****warning! can't do single < correctly try { while(f.read() !='>'); } catch (IOException e) {System.out.print("skipping <>"); c=-2;} continue;} sb.append((char)c);} s=sb.toString().toLowerCase(); //remove duplicate spaces sb.setLength(0); StringTokenizer st=new StringTokenizer(s," \t\n\r"); while (st.hasMoreTokens()) sb.append(st.nextToken()+" "); return sb.toString(); } public void init() { InputStream f; int i=0; String fontname; Font font; try { dit=new URL(getDocumentBase(),"dit.au"); dah=new URL(getDocumentBase(),"dah.au"); getAudioClip(dit); getAudioClip(dah);} catch (Exception e) { System.out.println("Trouble with audio clips"+e);} size=size(); setBackground(new Color(180,180,255)); filename=getParameter("fname"); // if ((fontname=getParameter("font"))==null) fontname="TimesRoman"; // font = new Font(fontname, Font.BOLD, size.height-1); // setFont(font); // fm=getFontMetrics(font); String att = getParameter("speed"); if (att != null) wpm=Integer.parseInt(att); //speed=60000/5/4/wpm;//calculate dit length for wpm speed=100; try {thisurl=new URL(getDocumentBase(),filename); f=thisurl.openStream();} catch (IOException e) {System.out.println("File not available");return;} message=glopFile(f); debug("message is:"+message); maxchars=message.length(); //read file try {f.close();} catch (IOException e) {System.out.print("can't close()");}} }