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{ Panel fileloader = new Panel(); Button startButton, stopButton; TextField slideshowname; Thread slidethread; Screen slidescreen; Slide SShow = new Slide(createImage(1,1), 0); Slide inView = SShow; public void init() { p("Running Slideviewer..."); stop(); String defaultSlideshow = getParameter("Default"); fileloader = new Panel(); slideshowname = new TextField(defaultSlideshow); startButton = new Button ("Start!"); slidescreen = new Screen(); setLayout(new GridLayout(1,1)); this.add(slidescreen); setBackground(Color.black); setForeground(Color.black); // this.add(fileloader); 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); try { p(" for "+inView.delay+" ms"); Thread.sleep(inView.delay); } catch (Exception x) { p(x); } inView = inView.next; } 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; start(); 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; start(); 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); } }