G
Giox
Good morning,
I have a problem with an applet using AWT MediaTracker class, and I
would like to know if someone else faced and solved this issue.
The code that I propose at the end of the post should read an image
and display it in an applet, refreshing it each time it is loaded.
This applet works fine with typical browser (IE and Firefox) and Java
1.5.XXXX, but doesn't work with the same browsers and Java 1.6.XXXX.
With this java version however everything works fine if I watch at the
applet in the appletviewer debugging it in Netbeans. Nothing happens
however if I watch at the applet in the web browser.
In fact it seems that the applet reads the image only the first time
it is loaded, but then changing the image on the hard disk doesn't
generate an update of the displayed image.
I set up a policy file where the applet is compiled using
grant {
permission java.security.AllPermission;
};
Please note that the applet doesn't crash since the
showStatus("Image Number: "+indexDisplayed);
doesn't stop updating.
I think that the code lines
tracker.removeImage(myImage);
myImage.flush();
should work correctly but it seems that Java 1.6 changed the meaning
of these instructions, when executed in a web browser.
In the next rows I propose a section of the applet.
Thanks a lot for your help.
Giovanni.
********************************
import java.awt.*;
import java.applet.*;
import java.net.*;
public class easyCamGio extends Applet {
private Image myImage = null;
private int indexDisplayed=0;
private String fileBase;
private String fileExtension;
private Thread timerThread;
private volatile boolean noStopRequested;
private MediaTracker tracker;
private void startThread() {
noStopRequested = true;
Runnable r = new Runnable() {
public void run() {
runWork();
}
};
timerThread = new Thread(r, "Timer");
timerThread.start();
}
private void runWork() {
boolean imageload = false;
try {
while ( noStopRequested ) {
// Get the image saved on the Hard Disk
myImage = getImage(getDocumentBase(), fileBase + "1" +
fileExtension);
// Add the image to MediaTracker
tracker.addImage(myImage, 0);
// Wait for the image
tracker.waitForAll();
imageload = true;
showStatus("Image Number: "+indexDisplayed);
indexDisplayed = indexDisplayed+1;
repaint();
// Remove the previously loaded image from the tracker and set it
to null
if( imageload == true ) {
tracker.removeImage(myImage);
myImage.flush();
myImage = null;
}
}
} catch ( InterruptedException x ) {
showStatus("runWork() Exception");
Thread.currentThread().interrupt();
}
}
}
********************************
I have a problem with an applet using AWT MediaTracker class, and I
would like to know if someone else faced and solved this issue.
The code that I propose at the end of the post should read an image
and display it in an applet, refreshing it each time it is loaded.
This applet works fine with typical browser (IE and Firefox) and Java
1.5.XXXX, but doesn't work with the same browsers and Java 1.6.XXXX.
With this java version however everything works fine if I watch at the
applet in the appletviewer debugging it in Netbeans. Nothing happens
however if I watch at the applet in the web browser.
In fact it seems that the applet reads the image only the first time
it is loaded, but then changing the image on the hard disk doesn't
generate an update of the displayed image.
I set up a policy file where the applet is compiled using
grant {
permission java.security.AllPermission;
};
Please note that the applet doesn't crash since the
showStatus("Image Number: "+indexDisplayed);
doesn't stop updating.
I think that the code lines
tracker.removeImage(myImage);
myImage.flush();
should work correctly but it seems that Java 1.6 changed the meaning
of these instructions, when executed in a web browser.
In the next rows I propose a section of the applet.
Thanks a lot for your help.
Giovanni.
********************************
import java.awt.*;
import java.applet.*;
import java.net.*;
public class easyCamGio extends Applet {
private Image myImage = null;
private int indexDisplayed=0;
private String fileBase;
private String fileExtension;
private Thread timerThread;
private volatile boolean noStopRequested;
private MediaTracker tracker;
private void startThread() {
noStopRequested = true;
Runnable r = new Runnable() {
public void run() {
runWork();
}
};
timerThread = new Thread(r, "Timer");
timerThread.start();
}
private void runWork() {
boolean imageload = false;
try {
while ( noStopRequested ) {
// Get the image saved on the Hard Disk
myImage = getImage(getDocumentBase(), fileBase + "1" +
fileExtension);
// Add the image to MediaTracker
tracker.addImage(myImage, 0);
// Wait for the image
tracker.waitForAll();
imageload = true;
showStatus("Image Number: "+indexDisplayed);
indexDisplayed = indexDisplayed+1;
repaint();
// Remove the previously loaded image from the tracker and set it
to null
if( imageload == true ) {
tracker.removeImage(myImage);
myImage.flush();
myImage = null;
}
}
} catch ( InterruptedException x ) {
showStatus("runWork() Exception");
Thread.currentThread().interrupt();
}
}
}
********************************