/* A basic extension of the java.applet.Applet class */ import java.awt.*; import java.applet.*; import java.net.*; import java.io.*; public class YahooMoviesCondenser extends Applet implements java.awt.event.ActionListener { public void init() { // Take out this line if you don't use symantec.itools.net.RelativeURL or symantec.itools.awt.util.StatusScroller // symantec.itools.lang.Context.setApplet(this); // This code is automatically generated by Visual Cafe when you add // components to the visual environment. It instantiates and initializes // the components. To modify the code, only use code syntax that matches // what Visual Cafe can generate, or Visual Cafe may be unable to back // parse your Java file into its visual environment. //{{INIT_CONTROLS setLayout(null); setSize(538,394); textFieldLink = new java.awt.TextField(); String LinkParameter = getParameter("Link"); textFieldLink.setText(LinkParameter); textFieldLink.setBounds(120,24,360,24); add(textFieldLink); label1 = new java.awt.Label("Yahoo Movies Link"); label1.setBounds(12,24,108,24); add(label1); textAreaMovies = new java.awt.TextArea(); textAreaMovies.setBounds(12,60,518,324); add(textAreaMovies); buttonGo = new java.awt.Button(); buttonGo.setActionCommand("button"); buttonGo.setLabel("Go!"); buttonGo.setBounds(492,24,40,24); buttonGo.setBackground(new Color(12632256)); add(buttonGo); //}} //{{REGISTER_LISTENERS // SymAction lSymAction = new SymAction(); textFieldLink.addActionListener(this); buttonGo.addActionListener(this); //}} } //{{DECLARE_CONTROLS java.awt.TextField textFieldLink; java.awt.Label label1; java.awt.TextArea textAreaMovies; java.awt.Button buttonGo; //}} // class SymAction implements java.awt.event.ActionListener // { public void actionPerformed(java.awt.event.ActionEvent event) { Object object = event.getSource(); if (object == textFieldLink || object == buttonGo) textFieldLink_EnterHit(event); } void textFieldLink_EnterHit(java.awt.event.ActionEvent event) { // to do: code goes here. String s = ""; textAreaMovies.setText(s); try { URL url = new URL(textFieldLink.getText()); //InputStream is = url.openStream(); //InputStreamReader isr = new InputStreamReader(url.openStream()); BufferedReader br = new BufferedReader(new InputStreamReader(url.openStream())); String line; while ((line = br.readLine()) != null) { s = s.concat(line) + '\n'; } // remove html codes int i,j; while ((i = s.indexOf('<')) >= 0 && (j = s.indexOf('>', i)) >= 0) { String code = s.substring(i+1, j); String replace = ""; code = code.toUpperCase(); if (code.compareTo("BR") == 0) replace = new String("\n"); else if (code.charAt(0) == '!') replace = '{' + code + '}'; if (i == 0) s = replace + s.substring(j+1); else s = s.substring(0, i) + replace + s.substring(j+1); } // replace nbsp; with a space while ((i = s.indexOf(" ")) >= 0) { if (i==0) s = ' ' + s.substring(i+6); else s = s.substring(0, i) + ' ' + s.substring(i+6); } s = s.replace('\r', '\n'); // remove blanks at end of line while ((i = s.indexOf(" \n")) >= 0) { if (i==0) s = s.substring(1); else s = s.substring(0, i) + s.substring(i+1); } // replace double blank lines with single blank line while ((i = s.indexOf("\n\n\n")) >= 0) { if (i==0) s = s.substring(1); else s = s.substring(0, i) + s.substring(i+1); } // remove up to first theatre if ((i = s.indexOf("{!-- THEATER --}")) > 0) { s = s.substring(i); } Movies movies = new Movies(s); s = "Yahoo! Movie Listings\n\n"; for (i=0; i