Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

java doesn't support javascript?

843807Mar 1 2010 — edited Mar 3 2010
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)

Comments

Processing
Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on Mar 31 2010
Added on Mar 1 2010
7 comments
140 views