It should be 'This is my first JavaScript! ' instead of a 'd '.
This is java code:
import javax.swing.*;
import java.awt.*;
import java.io.*;
import java.lang.Exception.*;
class Test extends JFrame
{ JLabel obj;
public Test()
{ setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setPreferredSize(new Dimension(800,600));
setContentPane(htmlGUI());
pack();
setVisible(true);
}
public JPanel htmlGUI()
{ JEditorPane htmlPane = new JEditorPane();
try
{ htmlPane.setPage(getClass().getResource("test.html")); //Nothing wrong with the url.
}catch (IOException e) {
System.err.println("Attempted to read a bad URL.");
}
htmlPane.setEditable(false);
JPanel p=new JPanel(new BorderLayout(0,0));
p.add(new JScrollPane(htmlPane));
return p;
}
public static void main(String[] args)
{ new Test();
}
}
Output:
d
(It only show a 'd' in the JEditorPane.)
This is html code:
<html>
<body>
<script type="text/javascript">
document.write("This is my first JavaScript!");
</script>
</body>
</html>
Output:
This is my first JavaScript!
(It is fine with internet browser)