import java.awt.*; import java.lang.Thread; import java.util.Vector; import java.net.URL; import java.net.MalformedURLException; public class banner extends java.applet.Applet implements Runnable{ final String defaultURL = "http://www.new-mediacom.com"; String headline; Vector headlines = new Vector(); Vector urls = new Vector(); int curHeadline =0; int stringPos =0; Thread runner; int textLevel; Image logo; Image offscreenImage; Graphics offscreenGraphics; Color textColor = Color.red; boolean myCursor = false; public void init() { setBackground(Color.black); //set up double buffering offscreenImage = createImage(size().width,size().height); offscreenGraphics = offscreenImage.getGraphics(); // get the sky logo logo = getImage(getCodeBase(),"sky.gif"); if (logo==null){ System.out.println("can't get image");} // get all the Headline and URL pairs. // can accept a variable number of parameters String h; for(int i = 1; true; i++) { // get the headline and add it to the Vector headlines h = getParameter(Integer.toString(i)); if(h == null) break; headlines.addElement(h); // get the corresponding url and add it to the Vector urls h = getParameter(Integer.toString(i)+"url"); if(h == null) h=defaultURL; // if there is no corresponding URL set it to the default urls.addElement(h); } } // boilerplate thread initialisation stuff public void start() { if (runner == null){ runner = new Thread(this); runner.start();} } // ditto public void stop() { if (runner != null){ runner.stop(); runner=null;} } // what we do whilst actually running public void run() { while (true) { // keep looping through all the headlines if (curHeadline >= headlines.size()){curHeadline=0;} // initialise some global variables textLevel=35; // what level the text will start at stringPos=0; // what position we are along the string headline = headlines.elementAt(curHeadline).toString(); // get the current headline for (stringPos=1;stringPos<=headline.length();stringPos++) { // make the cursor blink if (myCursor) myCursor=false; else myCursor=true; // draw the current headline segment then sleep repaint(); try {Thread.sleep(150);} catch (InterruptedException e){} } // let it stay for a bit on screen try {Thread.sleep(1000);} catch (InterruptedException e){} for (int a=1;a<35;a+=4) { // scroll it up stringPos = headline.length(); textLevel = 36-a; repaint(); try {Thread.sleep(150);} catch (InterruptedException e){} } curHeadline++; // get next headline } } public boolean handleEvent(Event evt) { // when mouse button is pressed jump the browser to this URL URL theURL; if (evt.id==Event.MOUSE_DOWN) { try { theURL = new URL(urls.elementAt(curHeadline).toString()); getAppletContext().showDocument(theURL);} catch ( MalformedURLException e) {} } if (evt.id==Event.MOUSE_MOVE) { showStatus(headlines.elementAt(curHeadline).toString()+" : "+urls.elementAt(curHeadline).toString()); textColor=Color.blue; } if (evt.id==Event.MOUSE_EXIT) { showStatus(""); textColor=Color.red; } return true; } public void paint(Graphics g) { // clear the screen offscreenGraphics.setColor(Color.black); offscreenGraphics.fillRect(0,0,size().width,size().height); // draw the sky logo if (logo != null){offscreenGraphics.drawImage(logo, 5, 10, this);} // draw the headline segment Font f = new Font("Arial,",Font.PLAIN, 15); offscreenGraphics.setFont(f); offscreenGraphics.setColor(textColor); offscreenGraphics.drawString(headline.substring(0,stringPos)+" |",115,textLevel); //draw on 'real' screen g.drawImage(offscreenImage,0,0,this); } public void update (Graphics g) { paint(g); } }