3

I have a simple test applet that's supposed to draw a little triangle (and works fine using appletviewer Triangle.class from the command line), but when I try to view Triangle.htm in my browser, I get this message (from Java itself, as far as I can tell, not my Firefox or Chrome):

"Your security settings have blocked a local application from running."

However, I can't figure out what settings to change. I tried just putting the general settings at their lowest (called "medium" ha ha what is this like cup sizes in a coffee shop-- Oh. Right.) but that didn't work, and if the solution is buried somewhere in the more advanced options, it's painfully non-obvious to me... :/

This question sounded like my problem:

Java Error: "Your security settings have blocked a local application from running"

But the original poster said, "Resolved: the problem was that the compiler used JDK6 instead of JDK7."

And I checked I had the latest version before re-compiling the class file:

> java -version
java version "1.7.0_25"
Java(TM) SE Runtime Environment (build 1.7.0_25-b17)
Java HotSpot(TM) Client VM (build 23.25-b01, mixed mode, sharing)

> javac Triangle.java

Anyway, can anyone see if they get the same problem and tell me how you fix it?

For easy replication, this is the source of the class file:

Triangle.java:

import java.awt.*;
import java.applet.Applet;
public class Triangle extends Applet {
    public void paint (Graphics g){
        int bottomX=80;
        int bottomY=200;
        int base=100;
        int height=100;
        g.drawLine(bottomX,bottomY,bottomX+base,bottomY);
        g.drawLine(bottomX+base,bottomY,bottomX+base/2,bottomY-height);
        g.drawLine(bottomX+base/2,bottomY-height, bottomX,bottomY);
    }
}

And this is the htm that's in the folder with the class file:

Triangle.htm:

<applet code="Triangle.class" width=400 height=400></applet>
Community
  • 1
  • 1
Owen_AR
  • 2,867
  • 5
  • 20
  • 23
  • what browser are you using? version? type? – Frank Jul 12 '13 at 11:25
  • check this out http://stackoverflow.com/questions/16196425/java-error-your-security-settings-have-blocked-a-local-application-from-runnin – Ruchira Gayan Ranaweera Jul 12 '13 at 11:26
  • @Frank, like I said, I tried both Firefox and Chrome so far (`22.0` and `28.0.1500.71 m` respectively). But the message seems to come from Java itself...? – Owen_AR Jul 12 '13 at 11:54
  • @Ruchira, I linked to that question in my question. Like I said, the OP said [they think] "the problem was that the compiler used JDK6 instead of JDK7." I only have `jdk1.7.0_25` installed. – Owen_AR Jul 12 '13 at 11:57
  • 1) Why code an applet? If it is due due to spec. by teacher, please refer them to [Why CS teachers should stop teaching Java applets](http://programmers.blogoverflow.com/2013/05/why-cs-teachers-should-stop-teaching-java-applets/). 2) Why AWT rather than Swing? See this answer on [Swing extras over AWT](http://stackoverflow.com/a/6255978/418556) for many good reasons to abandon using AWT components. If you need to support older AWT based APIs, see [Mixing Heavyweight and Lightweight Components](http://www.oracle.com/technetwork/articles/java/mixing-components-433992.html). – Andrew Thompson Jul 12 '13 at 12:18
  • @AndrewThompson Yes, it's for the retarded (in a very literal sense) specifications of a school project... – Owen_AR Jul 12 '13 at 12:24
  • @AndrewThompson "*please refer them to Why CS teachers should stop teaching Java applets*" I'm sorry, but... BUAHAHAHAHAH! The directions for this project include references to the "MS-DOS prompt", and a confusing irrelevant side-ramble about how to install a text editor that was last updated in 1999. xD Trying to "refer" these "teachers" to anything would be like trying to give feedback to a "doctor" who based his practice of Exsanguination-as-Panacea on the Theory of the Four Humours. ^^;;; – Owen_AR Jul 12 '13 at 12:26
  • @Ruchira So yeah, the "**This question may already have an answer here:**" message at the top of my question... Since I explicitly explained why that question *doesn't* have an answer to mine when I posted mine, do you think you could remove that? (If that's possible?) Thanks. – Owen_AR Jul 12 '13 at 12:30

2 Answers2

4

I just tried your code using Java version 1.7.0_25-b17. It works just fine in the browser on the two lower settings seen here.

Java Control Panel - Security Tab

To get it to work for the highest security level, it needs to be put in a Jar and signed using a valid certificate.

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
  • Hm. But that's exactly what I *did*... So I guess the next thing to try is just to completely uninstall and reinstall Java on both my desktop and netbook. Oh well, I'm more willing to do that now I know for a *fact* that it's possible to fix this problem, so thanks. ^^; (Also, I really like your gif there; Making communication as concrete as possible *rawks*. Do you have some sort of easy way to generate gifs of UI elements and stuff like that, or...?) – Owen_AR Jul 12 '13 at 13:56
  • 1
    @Owen_R It depends what you regard as 'easy'. I took 3 screenshots (using alt+print-screen to limit them to 'active' app.) pasted them in paint, cropped them (using keyboard accelerators) then saved them. I opened [GIFanim](http://pscode.org/gifanim/) to create the initial GIF. That produced a 49Kb animated GIF but I wanted it smaller, so took it over to http://www.gifreducer.com/ to cram it down to 32 colors and 35Kb. ..So no, not that easy, but I was bored and wanted a good animation of those levels anyway. ;) – Andrew Thompson Jul 12 '13 at 14:02
  • Heh. ^^; Anyway yeah, the complete uninstall/reinstall *then* slide the security down the "medium" worked. – Owen_AR Jul 12 '13 at 16:03
  • Oh, yeah, sure. Although I actually *had* tried adjusting the settings like that already (as I mentioned in the question as originally posted), and it didn't work until after I'd done the complete wipe and reinstall. – Owen_AR Jul 19 '13 at 15:42
0

It was officially stated (Oracle's response to my school-team's email) that some older remains of virtual machines may actually cause security alerts with applets even if you set security settings to absolute minimum (had it many times with my applet). I guess it is a school/study work (as it is an applet), so it is probably worth trying to run it directly by appletviewer.

3yakuya
  • 2,622
  • 4
  • 25
  • 40
  • Yeah, I said in my original post that I tested `appletviewer Triangle.class` and it worked, but... Well, my question was basically, "How do I get this kind of applet to run in my browser from an htm file and class file I have here in a folder on my hard-drive?", and you're saying you think the answer is "You can't. That's impossible now cuz of security updates."? – Owen_AR Jul 12 '13 at 12:40
  • Not exactly. As far as I understood the recommendation from Oracle, one should try removing exactly every part of Java's older versions. Probably the best way to achieve it would be making sure to remove virtually all Java VM stuff on your machine, and then reinstall the newest Java. I must admitt that among my teammates the problem with applets (home-made) did not occur at machines with exactly fresh system - and so only newest Java - indeed. – 3yakuya Jul 12 '13 at 14:32
  • (Yeah, I just got back from ripping all the Java stuff out by the roots, restarting, and reinstalling it from a fresh download. It works now. ... reminds me of the old joke where the car breaks down and the computer scientist says, "Let's try getting out of the car, opening and closing all the doors, then getting back in again"... ^^) – Owen_AR Jul 12 '13 at 16:02