The Artima Developer Community
Sponsored Link

Java Answers Forum
Java Refresh?

1 reply on 1 page. Most recent reply: Nov 7, 2002 5:11 PM by Clay Grace

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 1 reply on 1 page
Clay Grace

Posts: 2
Nickname: shaw101
Registered: Nov, 2002

Java Refresh? Posted: Nov 7, 2002 5:05 PM
Reply to this message Reply
Advertisement
I know this is possible but I'm not sure how. I am a php programmer and know only the basics of Java. I have a java file that opens a php page I created. The php page queries mysql and loads the hits and purchases of my tracking urls. Which is fine but the reason I am trying to do this with java is I want the stats updated without a crappy hard reload of the page. Is there a way to make the java file query my php page every 5 seconds and reload the stats? It would be better to do this all in java I'm sure but like I said I only know the basics that's why I have java interacting with php.

Thanks,
Clay

P.S. If it helps to see the source code I can post it or email it to you.


Clay Grace

Posts: 2
Nickname: shaw101
Registered: Nov, 2002

Re: Java Refresh? Posted: Nov 7, 2002 5:11 PM
Reply to this message Reply
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

Flat View: This topic has 1 reply on 1 page
Topic: Apache-Tomcat mod_jk  servlet mapping issue Previous Topic   Next Topic Topic: Problem with InputStreamReader

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use