Reputation: 553
I can't seem to get this jar running in html when I am using the new object tag for HTML 5. Do I need to add anything in order for this to work properly? This is how it look on the w3schools site, except they had it linked to a .swf file.
<object height = "800" width="600" data="ECPrototype.jar"></object>
UPDATE WITH CODE:
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();
}
}
Upvotes: 0
Views: 248
Reputation: 9609
Found here and tested on my computer:
<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>
About the frame issue, try rewriting constructor, init and 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);
}
Upvotes: 1
Reputation: 1623
Try
<applet code=TicTacToe.class
archive="ECPrototype.jar"
width=120 height=120>
</applet>
(The class has your main() I assume, the jar is the entire thing)
Upvotes: 0