Hejsa alle!
Jeg har et problem med et applet jeg er ved at lave. Det skal vise et
billede fra et webcam (som bliver distribueret over en bestemt port fra min
computer) med den her adresse:
http://xxx.xxx.xxx.xxx:8181 (altså, port 8181
på min ip). Det virker fint nok i applet-viewer i JBuilder, men ikke i
Internet Explorer. Koden ses nedenunder. Vær rar og hjælp mig!!!
Venlig hilsen mig
package webcam;
import java.awt.*;
import java.applet.*;
import javax.swing.*;
import java.net.*;
import java.util.*;
public class Webviewer extends JApplet {
private Image i;
private URL url;
private Thread traad;
private String s;
private Image off;
private MediaTracker tracker;
private Updater up;
public void init() {
up = new Updater(this);
tracker = new MediaTracker(this);
traad = new Thread(up);
try {
url = new URL("
http://xxx.xxx.xxx.xxx:8181");
} catch (MalformedURLException e) {
System.out.println("URL-fejl: " + e.toString());
}
off = getImage(this.getCodeBase(), "offline.gif");
i = getImage(url);
tracker.addImage(off, 0, 176, 144);
tracker.addImage(i, 1, 176, 144);
setSize(176,144);
try {
tracker.waitForID(0);
} catch (InterruptedException e) {
System.out.println("Wait-fejl: " + e.toString());
}
traad.start();
}
public void time() {
s = "/?" + String.valueOf(new Date().getTime());
i = getImage(url, s);
tracker.addImage(i, 1, 176, 144);
repaint();
}
public void paint(Graphics g) {
try {
tracker.waitForID(1);
} catch (InterruptedException e) {
System.out.println("Wait-fejl: " + e.toString());
}
if (tracker.isErrorID(1))
g.drawImage(off, 0, 0, this);
else
g.drawImage(i, 0, 0, this);
tracker.removeImage(i, 1);
up.go();
}
}
_______________
package webcam;
public class Updater implements Runnable{
private Webviewer a;
public void run() {
go();
}
synchronized public void go() {
a.time();
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
}
}
public Updater(Webviewer w) {
a = w;
}
}