0
Well, I made a program in applet, (extending the Japplet class) and generated the file . jar, put it in a folder and wrote an HTML page to run it:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><title>Engineer's Showdown</title>
</head>
<body style="background-color:black;">
<center>
<applet code="pack.game.Applet.class" archive="engineers_applet.jar" width="1024" height="768"
style="color:white;">
Applet tag
</applet>
<br/>
<object archive="engineers_applet.jar" classid="java:pack.game.Applet.class" codetype="application/java"
width="1024" height="768" style="color:white;">
Object tag
</object>
</center>
</body>
When accessing the site, the applet simply does not run, when I press F12 to see the console, also nothing appears, if it is also useful, here is my Applet class.java:
package pack.game; import java.awt.Color; import java.awt.Cursor; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.Point; import java.awt.Toolkit; import java.awt.event.KeyEvent; import java.awt.event.KeyListener; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; import java.awt.event.MouseMotionListener; import java.awt.event.MouseWheelEvent; import java.awt.event.MouseWheelListener; import java.awt.image.BufferedImage; import java.awt.image.VolatileImage;
import javax.swing.Japplet;
import engine.window.Manager; import engine.window.Dashboard; import engine.window.Window; import pack.objects.Res; import pack.states.Ending; import pack.states.Game; import pack.states.Menu;
public class Applet extends Japplet Implements Runnable, Keylistener, Mouselistener, Mousemotionlistener, Mousewheellistener{
/**
*
*/
private static final long serialVersionUID = 1L;
Thread thread;
VolatileImage img;
Graphics2D g;
double delta;
double FPS = 60;
double targetTime = 1000.0/FPS;
public void start(){
img = createVolatileImage(1024, 768);
g = img.createGraphics();
setFocusTraversalKeysEnabled(false);
thread = new Thread(this);
addKeyListener(this);
addMouseListener(this);
addMouseMotionListener(this);
addMouseWheelListener(this);
thread.start();
setFocusable(true);
requestFocus();
Window.width = 1024;
Window.height = 768;
}
public void init(){
Main.loadPonyAnimations();
Main.loadWeaponImages();
Res.load();
// Transparent 16 x 16 pixel cursor image.
BufferedImage cursorImg = new BufferedImage(16, 16, BufferedImage.TYPE_INT_ARGB);
// Create a new blank cursor.
Cursor blankCursor = Toolkit.getDefaultToolkit().createCustomCursor(
cursorImg, new Point(0, 0), "blank cursor");
setCursor(blankCursor);
Manager.addState(new Menu());
Manager.addState(new Game());
Manager.addState(new Ending());
}
public void paint(Graphics g){
g.drawImage(img, 0, 0, null);
}
public void run() {
long startTime;
long elapsedTime;
initialize();
while(true){
startTime = System.nanoTime();
update();
draw();
elapsedTime = System.nanoTime() - startTime;
while(elapsedTime/1000000.0 < targetTime){
elapsedTime = System.nanoTime() - startTime;
}
delta = (System.nanoTime() - startTime)/1000000.0;
}
}
public void initialize(){
Manager.init();
}
public void update(){
Manager.update((float) delta);
}
public void draw(){
g.setColor(Color.black);
g.fillRect(0, 0, Window.width, Window.height);
g.setColor(Color.white);
Manager.draw(g);
repaint();
}
public void mouseDragged(MouseEvent m) {
Painel.MouseX = m.getX();
Painel.MouseY = m.getY();
}
/**
* Recebe quando o mouse foi movimentado dentro da tela
*/
public void mouseMoved(MouseEvent m) {
Painel.MouseX = m.getX();
Painel.MouseY = m.getY();
}
/**
* Recebe quando o mouse foi clicado
*/
public void mouseClicked(MouseEvent m) {
}
/**
* Recebe quando o mouse entrou na tela
*/
public void mouseEntered(MouseEvent m) {
Painel.MouseX = m.getX();
Painel.MouseY = m.getY();
}
/**
* Recebe quando o mouse saiu da tela
*/
public void mouseExited(MouseEvent m) {
Painel.MouseX = m.getX();
Painel.MouseY = m.getY();
}
/**
* Recebe quando o mouse foi pressionado
*/
public void mousePressed(MouseEvent m) {
Manager.mousePressed(m.getButton());
}
/**
* Recebe quando o mouse foi solto
*/
public void mouseReleased(MouseEvent m) {
Manager.mouseReleased(m.getButton());
}
/**
* Recebe quando uma tecla foi pressionada
*/
public void keyPressed(KeyEvent e) {
Manager.keyPressed(e);
}
/**
* Recebe quando uma tecla foi solta
*/
public void keyReleased(KeyEvent e) {
Manager.keyReleased(e);
}
/**
* Recebe quando uma tecla foi digitada
*/
public void keyTyped(KeyEvent e) {
}
public void mouseWheelMoved(MouseWheelEvent m) {
Manager.mouseWheelMoved(m);
}
}
Also a print of the page, and of my folder:
What am I doing wrong? I need to do something with this . jar before?
Unless you have a very specific need to use applets, simply don’t use.
– utluiz