views:

55

answers:

1

I currently have a tiny Java applet I'm writing to solve a specific problem in our company intranet in a browser neutral way. This used to be accomplished with ActiveX but we'd like to let people move away from IE. The code is obviously unsafe for public consumption, but it's useful under controlled circumstances. Essentially I want the user to be able to click a link in their and open an application installed on the local machine based on data returned from an AJAX call. This is a signed Java applet and the certificate has been accepted on the local machine.

Currently this works perfectly in IE and Opera, but it fails in Chrome and Safari. It appears that the repaint() method doesn't actually cause a repaint, which I am struggling with. Here's the applet code:

import java.applet.Applet;
import java.awt.Graphics;
import java.util.*;

public class OdehAppLauncher extends Applet {

    private ArrayList<String> toRun = null;

    public void paint(Graphics g) {
        System.out.println("-----painting");
        try {
            if (toRun != null) {
                new ProcessBuilder(toRun).start();
                toRun = null;
            }

        } catch (Exception e) {
            System.out.println("-----Exception e = " + e);
            e.printStackTrace();
        }
    }

    public void runApp(String appName, String args) {
        System.out.println("-----running app: " + appName);
        toRun = new ArrayList<String>(2);
        toRun.add(appName);
        toRun.add(args);
        System.out.println("-----triggering a repaint...");
        repaint();
    }
}

Here are the last few lines of the Java Console for each of the four tested browsers when the runApp method is called:

IE 9 (beta) - works:

basic: Applet started
basic: Told clients applet is started
-----painting
-----running app: notepad.exe
-----triggering a repaint...
-----painting

Safari 5.0.2 (7533.18.5) - fails

liveconnect: JavaScript: default security policy =
-----running app: notepad.exe
-----triggering a repaint...

Opera 10.62 - works

basic: Applet started
basic: Told clients applet is started
-----painting
-----painting
-----painting
-----running app: notepad.exe
-----triggering a repaint...
-----painting

Chrome 6.0.472.63 - fails

basic: Applet started
basic: Told clients applet is started
-----running app: notepad.exe
-----triggering a repaint...

Please let me know if you can think of any reason why this isn't behaving consistently (or a better way to do this in general). I should also point out that I've tried just launching the process directly from the runApp call, but that fails universally.

+1  A: 

Maybe this link gives a few hints. For instance:

NOTE: If multiple calls to repaint() occur on a component before the initial repaint request is processed, the multiple requests may be collapsed into a single call to update(). The algorithm for determining when multiple requests should be collapsed is implementation-dependent. If multiple requests are collapsed, the resulting update rectangle will be equal to the union of the rectangles contained in the collapsed requests.

You might want to check if the applet is visible, if there has been a paint recently, and if update(Graphics) is called...

Damien