Clay Grace
Posts: 2
Nickname: shaw101
Registered: Nov, 2002
|
|
Re: Java Refresh?
|
Posted: Nov 7, 2002 5:11 PM
|
|
I think I will just go ahead and include the source code here:
import java.awt.*; import java.applet.*; import java.net.*; import java.io.*;
public class ReadsFromURL extends Applet { /*=======================================================*/ /* I N S T A N C E V A R S */ /*=======================================================*/
/** * Location of the file to read in */ protected URL fileURL; //fileURL = "http://mycheapcigarettes.com/livestats.php"; /** * A String holding the contents read from the server */ protected String result;
/** * A TextArea for display */ protected TextArea ta;
/** * Margin */ protected int off = 15;
/*=======================================================*/ /* C O N S T R U C T O R S */ /*=======================================================*/ /** * Default constructor * */ public ReadsFromURL() { ; // default constructor for some fussy VMs }
/** * initialize the applet * * @see #readInURL() readInURL * */
public void init() { setBackground(Color.lightGray); ta = new TextArea();
/* * set to a monospaced font; we can't assume * Courier is available */ ta.setFont(new Font("Monospaced", Font.BOLD, 12));
/* * Set server to read applet source code */ try { fileURL = new URL(getCodeBase() + "livestats.php"); } catch(MalformedURLException e) { showStatus("Error: " + e.getMessage()); }
/* * Layout the container */ this.setLayout(null); // ack! Not always wise
add(ta);
/* * Must setBounds because of null layout */ ta.setBounds(getSize().width/8, getSize().height/8, getSize().width*3/4, getSize().height*3/4);
/* * Load the file */ readInURL(); }// init
/*=======================================================*/ /* N E T W O R K I N G */ /*=======================================================*/
/** * * Read the URL -- this method reads in the URL's stream, * wrapping it in a BufferdReader. Nothing is returned; * an instance variable is instead used to hold the * stream contents. * */
public void readInURL() { try { String strTemp; java.io.InputStream input = fileURL.openStream(); BufferedReader buff = new BufferedReader (new InputStreamReader(input)); while((strTemp = buff.readLine()) != null) ta.append(strTemp+"\n");
/* be a good net neighbor and close the stream */ buff.close(); }
catch(IOException dammit) { showStatus("Exception: " + dammit.getMessage()); }
}// readInURL
}// class ReadsFromURL
|
|