0

当我使用 HTML 5 的新对象标签时,我似乎无法让这个 jar 在 html 中运行。我需要添加任何东西才能使其正常工作吗?这是 w3schools 网站上的外观,除了他们将其链接到 .swf 文件。

<object height = "800" width="600" data="ECPrototype.jar"></object>

更新代码:

import java.applet.Applet; 
import java.awt.Dimension;         
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;

import javax.swing.JFrame;
import javax.swing.Timer;


public class EC extends Applet implements ActionListener{
    private static final long serialVersionUID = 1L;
    Animation test= new Animation();
    Timer timer= new Timer(5,this);
    Thread thread = new Thread(test);
    Thread t = null; 
    public void init() {
    }
     public void stop() {
    }
    public void actionPerformed(ActionEvent e) {
        test.move();
        test.update();
        test.repaint();
    }

    private class TAdapter extends KeyAdapter implements ActionListener {

        public void keyReleased(KeyEvent e) {
            test.keyReleased(e);
            test.stopAnimation();
        }

        public void keyPressed(KeyEvent e) {
            test.keyPressed(e);
            test.startAnimation();
            t= new Thread(test.animate);
            t.start();
        }

        @Override
        public void actionPerformed(ActionEvent e) {
            // TODO Auto-generated method stub
        }
    }
    public EC()
    {
        thread.start();
        timer.start();
        JFrame window=new JFrame("EC");
        window.setPreferredSize(new Dimension(800,600));
        window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        window.add(test);
        window.addKeyListener(new TAdapter());
        window.setFocusable(true);
        window.pack();
        window.setVisible(true);
    }
    public static void main(String args[])
    {
        new EC();
    }
}
4

2 回答 2

1

在这里找到并在我的电脑上测试:

<object type="application/x-java-applet" width="400" height="400">
    <param name="code" value="name.of.your.Applet">
    <param name="archive" value="YourJarFile.jar">
</object>

关于框架问题,尝试重写构造函数、init 和 main:

    public void init() {
        addKeyListener(new TAdapter()); // only executed in applet
    }
    public EC() {
        // executed in both applet and application
        thread.start();
        timer.start();
    }
    public static void main(String args[]) {   
        // only executed in application
        EC ec = new EC();
        JFrame window=new JFrame("EC");
        window.setPreferredSize(new Dimension(800,600));
        window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        window.add(ec.test);
        window.addKeyListener(ec.new TAdapter());
        window.setFocusable(true);
        window.pack();
        window.setVisible(true);
    }
于 2013-08-01T04:03:11.787 回答
0

尝试

    <applet code=TicTacToe.class 
    archive="ECPrototype.jar"
    width=120 height=120>
    </applet>

(我假设这个类有你的 main(),jar 就是全部)

于 2013-08-01T03:59:38.633 回答