Meaningless Drivel is fun!*
The moose likes Applets and the fly likes Applet Cache Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Applets
Bookmark "Applet Cache" Watch "Applet Cache" New topic
Author

Applet Cache

Ganesh Sundaresan
Ranch Hand

Joined: Feb 09, 2006
Posts: 36
Hi,

I am using a applet to paint a Bar Chart. The applet will take the input from a text file and paint the chart. Each time when a different input is given from front end (JSP) the text file gets updated with new data and the applet draws the chart according to the text file data.

When I give a input from front end for the first time the Applet paints the chart correctly accordng to the data in the text file but when I change the input the applet shows the same (previous) chart(from cache) and it does not paint the new chart with the new value.

I tried clearing the cache from java console and also tried adding
image.flush() in applets stop method.

Nothing works. It will be great if anyone help me on this.

Thanks in advance
Ganesh


Thanks, Ganesh
SJCP (95%), SCWCD (75%), SCDJWS (Planning to take....)
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41107
    
  45
Welcome to JavaRanch.

Just to make sure I understand the architecture: There is an HTML form into which the user enters some data. This is then submitted to the server, where the data is written to a file. Then you redirect to the applet page, and then the applet retrieves the file from the server and paints the chart. OK?

Is the file actually updated?
Does the applet retrieve the file successfully, and gets the new values?


Ping & DNS - my free Android networking tools app
sinasi susam
Ranch Hand

Joined: Jul 15, 2005
Posts: 67
This problem may caused for many reasons.
First is as the previous answer said make sure if the updated values coming correctly from the server.you can print the file content to java console by System.out. or Swing's JOptionPane in orrder to be sure whether its correctly coming or not.

Second is if its coming correctly the there must be a failure with repainting.
for example if you are using double buffering maybe you forgot to flush the last graphic?

ummm I dont know any other?i must see to say you more and know more about the structure..
Ganesh Sundaresan
Ranch Hand

Joined: Feb 09, 2006
Posts: 36
Hi ,

Thanks for ur reply.

Ulf Dittmer, u got the architecture correct. The file has the updated values. but the applet is just looking at the cache and displaying the previous image.

sinasi susam , I disabled caching and also tried flushing the image.

I suspect it is refering classloader cache anyways to clean up this cache
programatically or disable this cache ??

I can send u the applet class if u give ur mail id.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41107
    
  45
How do you read the file? Is it on a shared drive so the applet can get at it? Or is it in the applet directory in the web server, and you're using the classloader and an inputstream?

Are you using JFreeChart by any chance? Its CategoryDataset and its subclasses cache dataset information if the parameters are unchanged. The solution to that would be to add a dummy parameter that changes every time.
Ganesh Sundaresan
Ranch Hand

Joined: Feb 09, 2006
Posts: 36
Hi,
Thanks for the reply. Find below the details u asked

Inside Appllet class
**************************

addImage = getParameter("chartdata"); // gives the txt file name
if(addImage != "" && addImage != null)
addElement(addImage);



private void addElement(String s)
{
boolean flag = false;
flag = addMouseListener(s); // loads the data file find method below
if(flag)
{
Enumeration enumeration = append.elements();
do
{
if(!enumeration.hasMoreElements())
break;
addImage = (String)enumeration.nextElement();
if(!addImage.startsWith("<!-"))
{
String s1 = " ";
String s2 = " ";
j = addImage.indexOf("= ");
if(j > 0)
{
s1 = addImage.substring(0, j).trim();
s2 = addImage.substring(j + 1).trim();
}
j = 0;
while(j < getY[3])
{
for(i = 0; i < getY[1]; i++)
if(s1.equals("data" + (i + 1) + "series" + (j + 1)) && s2 != "" && s2 != null)
CalcLegend(s2, j, i);

j++;
}
}
} while(true);
}
}


private boolean addMouseListener(String s)
{
boolean flag = true;
URL url = null;
try
{
url = new URL(getCodeBase(), s);
}
catch(MalformedURLException malformedurlexception)
{
System.out.println("Bad URL for File Location : " + s);
flag = false;
}
Object obj = null;
Object obj1 = null;
append = new Vector(); // declared as instance variable
try
{
URLConnection urlconnection = url.openConnection();
urlconnection.connect();
BufferedReader bufferedreader = new BufferedReader(new InputStreamReader(urlconnection.getInputStream(), auto_scale));
while((addImage = bufferedreader.readLine()) != null)
append.addElement(addImage);
}
catch(IOException ioexception)
{
System.out.println("IO Error:" + ioexception.getMessage());
flag = false;
}
return flag;
}



data file (txt file ) content
*******************************
#Traffic values
#Fri Feb 17 14:41:16 PST 2006
data1series6=147
data1series5=188
data1series4=243
data1series3=318
data1series2=329
data1series1=493
Ganesh Sundaresan
Ranch Hand

Joined: Feb 09, 2006
Posts: 36
The txt file is in the webserver
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41107
    
  45
If the file is served by the web server, make sure it doesn't get cached there.

I'm still not sure if the applet actually reads the updated values, and just doesn't display them, or if it doesn't read the updated values?

On an unrelated note: why would a method retrieving data over a network be named "addMouseListener"?
Ganesh Sundaresan
Ranch Hand

Joined: Feb 09, 2006
Posts: 36
Hi,

Thanks for ur reply.
The problem was Proxy cache. I changed Browser settings and it worked.

Thanks for ur help.
 
 
subject: Applet Cache
 
Similar Threads
Applet displays grey box, but applet is started
How can I paint a chart in the jsp
XmlEncoder with Applet
JSlider not displaying
Applets and JSPs