import java.applet.Applet; import java.awt.*; import java.awt.image.*; import java.io.*; import java.net.*; import java.util.StringTokenizer; public class SlideViewer extends Applet implements Runnable{ Button startButton, stopButton; TextField slideshowname; Thread slidethread; Screen slidescreen; Slide SShow = new Slide(createImage(1,1), 0); Slide inView = SShow; Image fg, focus; public void init() { stop(); p("Running Slideviewer..."); setBackground(Color.black); setForeground(Color.black); Image blank = createImage(320,240); // slidescreen.showImage(blank); String defaultSlideshow = getParameter("Default"); // THIS SECTION IS NEW!!! String focusimage = getParameter("FocusImage"); String fore = getParameter("Foreground"); fg = getImage(getCodeBase(), fore); focus = getImage(getCodeBase(), focusimage); MediaTracker mt = new MediaTracker(this); mt.addImage(fg, 1); mt.addImage(focus, 2); try{ mt.waitForAll(); } catch (Exception e) { System.out.println(e); } // NOT NEW ANYMORE. slideshowname = new TextField(defaultSlideshow); startButton = new Button ("Start!"); slidescreen = new Screen(); setLayout(new GridLayout(1,1)); this.add(slidescreen); slidescreen.repaint(); loadSlideShow(slideshowname.getText()); } public void run() { p("Slidemonitor running"); while (inView != null) { System.out.print("Showing image: "+inView.img); slidescreen.showImage(inView.img); slidescreen.showImage(fg); try { p(" for "+inView.delay+" ms"); Thread.sleep(inView.delay); } catch (Exception x) { p(x); } inView = inView.next; } slidescreen.showImage(focus); stop(); } public void start() { slidethread = new Thread(this, "foo"); } public void stop() { slidethread = null; } public boolean mouseUp (Event e, int x, int y) { if (e.target instanceof Screen) { inView = SShow.next; slidethread = new Thread(this, "foo"); slidethread.start(); } return true; } public boolean action (Event e, Object arg) { if ((e.target instanceof TextField) || (e.target instanceof Button)) { loadSlideShow(slideshowname.getText()); inView = SShow.next; slidethread.start(); } return true; } private InputStream getSlideShow(String showname) { InputStream ss = null; // p("Loading slideshow: "+showname); // try { //ss = (new URL(showname)).openStream(); //} //catch (Exception e) { //p(e); //p("Cannot read file: "+showname); p("Loading: "+getCodeBase()+showname); try { ss = (new URL(getCodeBase()+showname)).openStream(); } catch (Exception x) { p(x); } // } return ss; } public void loadSlideShow(String showname) { String next = "dummyvalue"; SShow.img = createImage(1,1); Slide currSlide = SShow; String im; try { DataInputStream ds = new DataInputStream(getSlideShow(showname)); while ((next = ds.readLine()) != null) { // p("LINE: "+next); if (next != "") { StringTokenizer st = new StringTokenizer(next, " \t"); currSlide.next = new Slide(loadImage(st.nextToken()), Integer.parseInt(st.nextToken())); currSlide = currSlide.next; } } } catch (Exception e) { // p(e); } } public Image loadImage(String newImagename) { Image canv = null; // try{ p("Loading image: "+newImagename); // canv = getImage(new URL(newImagename)); //} //catch (Exception e) { //p(e); //p("Trying alternate: "+getCodeBase()+newImagename); try { canv = getImage(new URL(getCodeBase(),newImagename)); } catch (Exception x){ p(x); //} } MediaTracker mt = new MediaTracker(this); mt.addImage(canv, 0); try{ mt.waitForID(0); } catch (Exception e){ System.out.println(e); } return canv; } private void p(String s) { System.out.println(s); } private void p(Exception e) { System.out.println(e); } }