// CodeBase.java import java.awt.Graphics; import java.applet.Applet; import java.net.*; import java.io.*; public class CodeBase extends Applet { double f(double x) { double vl=0; for (int i=1, j=1; i < 17; i+=2) { vl += j* ( Math.cos(i*x/50.0) / i ); j*=-1; } return vl*60+200; } public void paint(Graphics g) { for (int x = 0 ; x < getSize().width ; x+=1) { g.drawLine(x, (int)f(x), x + 1, (int)f(x + 1)); } try {URL testRead = new URL(getCodeBase(),"data"); String url = testRead.toString(); BufferedReader in = new BufferedReader(new InputStreamReader(testRead.openStream())); String buffer; int ypos=20; g.drawString(url,0,10); while (!(null==(buffer=in.readLine()))) {g.drawString(buffer,0,ypos); ypos+=10;} } catch(MalformedURLException e) {System.out.println("Failed to create URL:\n" + e);} catch(IOException e) {System.out.println("File error:\n" + e);} } }