// Text frame class that extends Frame // Date: 3-9-99 // Give applet access to all the AWT toolkit libraries import java.awt.*; import java.awt.event.*; import java.net.*; import java.io.*; import java.applet.*; public class textframe extends Frame implements ActionListener, ItemListener, MouseListener{ // declare variables public URL fileURL; public int imageRow = 0; public int imageCol = 0; public String text, start; public String end = "END"; public TextArea content; public InputStream input = null; public DataInputStream data; // constructor with user interaction components public textframe (String s, int row, int col){ super (s); // call base class constructor to set frame title imageRow = row; imageCol = col; addMouseListener (this); addWindowListener (new closewindow()); setBackground (Color.white); content = new TextArea ("Loading Data ...", 35, 50); add(content); showText(); } public void showText(){ /* //use this block to read file from hard disk; comment out the block below try{ input = new FileInputStream ("text.txt"); } catch (IOException e){ java.lang.System.err.println ("Unable to open file\n: " + e.toString()); } */ //use this block to read file via Internet try{ //gets file fileURL = new URL("http://www.aud.ucla.edu/~lms/text.txt"); } catch (MalformedURLException e){ java.lang.System.err.println ("Unable to open file\n: " + e.toString()); } start = "TEXT" + imageRow + imageCol; try{ //create data stream input = fileURL.openStream(); data = new DataInputStream (input); //content.setFont (new Font("TimesRoman", Font.BOLD, 14)); content.setText (""); while ((text = data.readLine()) != null){ if (text.equals(start)){ while (((text = data.readLine()) != null) && (text.equals(end) == false)){ content.appendText (text + "\n"); System.out.println ("String text = " + text); } } } //content.addNotify(); content.select(1,1); data.close(); //finished reading, now close stream System.out.println ("Data closed"); } catch (IOException e){ java.lang.System.err.println ("Exception: " + e.toString()); } try{ //now close file input.close(); System.out.println ("Input closed"); } catch (IOException e){ java.lang.System.err.println ("Unable to close file\n: " + e.toString()); } content.show(); } public void newText (int row, int col){ imageRow = row; imageCol = col; showText(); } public void mousePressed (MouseEvent e){} public void mouseClicked (MouseEvent e) {} public void mouseEntered (MouseEvent e) {} public void mouseExited (MouseEvent e) {} public void mouseMoved (MouseEvent e) {} public void mouseReleased (MouseEvent e) {} public void actionPerformed (ActionEvent e) {} public void itemStateChanged (ItemEvent e){} }