I've made a simple JAVA program to show a HTML page. But I cant seem to get the JAVA SCRIPT on the html page to work in the program. I use it to make calculations. If I open the HTML page in the browser it does work. Can someone help how i also get it to work in my JAVA program?
Below you'll find the code.
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package javaapplication16;
import javax.swing.JEditorPane;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import java.io.FileReader;
/**
*
* @author chris
*/
public class JavaApplication16 {
/**
* @param args the mand line arguments
*/
public static void main(String[] args) throws Exception {
String url = "/";
JEditorPane editor = new JEditorPane("/");
editor.setEditable(true);
JScrollPane pane = new JScrollPane(editor);
JFrame f = new JFrame("calculatie Program");
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.getContentPane().add(pane);
f.setSize(800, 600);
f.setVisible(true);
}
}
I've made a simple JAVA program to show a HTML page. But I cant seem to get the JAVA SCRIPT on the html page to work in the program. I use it to make calculations. If I open the HTML page in the browser it does work. Can someone help how i also get it to work in my JAVA program?
Below you'll find the code.
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package javaapplication16;
import javax.swing.JEditorPane;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import java.io.FileReader;
/**
*
* @author chris
*/
public class JavaApplication16 {
/**
* @param args the mand line arguments
*/
public static void main(String[] args) throws Exception {
String url = "http://members.multimania.nl/c75/";
JEditorPane editor = new JEditorPane("http://members.multimania.nl/c75/");
editor.setEditable(true);
JScrollPane pane = new JScrollPane(editor);
JFrame f = new JFrame("calculatie Program");
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.getContentPane().add(pane);
f.setSize(800, 600);
f.setVisible(true);
}
}
Share
Improve this question
asked Sep 13, 2012 at 14:13
user1668855user1668855
231 silver badge3 bronze badges
4 Answers
Reset to default 2Standard java ponents support very basic HTML only. They do not support either JavaScript or any advanced elements introduced during that last 10 (or may be even 15) years.
You should use pure java browser. There are several implementations. The following discussion may help you: Pure Java HTML viewer/renderer for use in a Scrollable pane
JEditorPane
doesn't support Javascript. The easiest alternative would be to use either JxBrowser (mercial) or SWT's Browser widget.
Try using Rhino to process the javascript... Otherwise it's a dead end.
Please take a look at the swt browser ponent, but I too would remend rhino, if all you want is running putations written in js.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745199617a4616260.html
评论列表(0条)