簡體   English   中英

Java Applet + HTML

[英]Java Applet + HTML

我在將applet嵌入html文件時遇到問題。 我在瀏覽器中看到“找不到類定義錯誤”。 這是與MySQL數據庫連接的簡單applet。 這是代碼:

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);           
        }
    }

這是我的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>

我不知道它在html或其他路徑中是否錯誤?

嘗試這個。

 <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>

如果要將Applet運行到瀏覽器中,則必須首先簽名JAR文件。 以下是更多詳細信息的參考:

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