简体   繁体   English

Java Applet + HTML

[英]Java Applet + HTML

I have a problem with embedding my applet in html file. 我在将applet嵌入html文件时遇到问题。 I've got "no class def found error" in browser. 我在浏览器中看到“找不到类定义错误”。 This is the simple applet connected with MySQL database. 这是与MySQL数据库连接的简单applet。 This is the code: 这是代码:

public class Nowy extends JApplet {

JPanel panel;
JButton count, end;
JLabel result;
int score;
String name = "Matthew";

    @Override
    public void init() {
        panel = new JPanel();
        panel.setLayout(null);
        add(panel);

        result = new JLabel("0");
        result.setBounds(10,10,100,30);
        panel.add(result);

        count = new JButton("COUNT");
        count.setBounds(10,60,100,30);
        panel.add(count);

        end = new JButton("END");
        end.setBounds(130,60,100,30);
        panel.add(end);   

        count.addActionListener(new ActionListener() {
           @Override
           public void actionPerformed(ActionEvent e) {            
               score = score + 5;
               result.setText(""+score);
           }
        }); 

        end.addActionListener(new ActionListener() {
           @Override
           public void actionPerformed(ActionEvent e) {            
               con();
           }
        });       
    }

    public void con() {
        try{
            Connection con = DriverManager.getConnection("jdbc:mysql://localhost/res", "root", "");
            Statement stmt = (Statement) con.createStatement();           
            String insert = "INSERT INTO wyniki VALUES ('" + score + "', '" + name + "')";            
            stmt.executeUpdate(insert);

        }catch (Exception e) {
            System.out.println(e);           
        }
    }

And this is my html code: 这是我的html代码:

<applet code = 'Nowy.class' 
    archive = 'Nowy.jar mysql-connector-java-5.1.27-bin.jar'
    width = 300
    height = 300>
    <param name="permissions" value="sandbox" />
</applet>

I have no idea if it's wrong path in html or other? 我不知道它在html或其他路径中是否错误?

Try this. 尝试这个。

 <script src="//www.java.com/js/deployJava.js"></script>
    And this to <body> section:

    <script>
        var attributes = {codebase: 'http://my.url/my/path/to/codebase',
                          code: 'my.main.Applet.class',
                          archive: 'my-archive.jar',
                          width: '800', 
                          height: '600'};
        var parameters = {java_arguments: '-Xmx256m'}; // customize per your needs
        var version = '1.5'; // JDK version
        deployJava.runApplet(attributes, parameters, version);
    </script>

If you want to run your Applet into Browser than you must have to signed your JAR file first. 如果要将Applet运行到浏览器中,则必须首先签名JAR文件。 Here is the reference for more details: 以下是更多详细信息的参考:

http://www-personal.umich.edu/~lsiden/tutorials/signed-applet/signed-applet.html http://www-personal.umich.edu/~lsiden/tutorials/signed-applet/signed-applet.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM