I have a desktop Java game I’d like to run on a browser. Some people say I need to use Applet or JApplet for this but I haven’t caught a straight answer.
I’m using JFrame, BufferStrategy & Thread if that’s relevant in any way and here’s the code of interest:
public class Game extends Canvas implements Runnable {
public static void main(String[] args) {
Game g = new Game();
g.addKeyListener(new Input());
g.setFocusable(true);
JFrame f = new JFrame("OMG A TITLE");
f.add(g);
f.pack();
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setSize(W, H);
f.setResizable(false);
f.setLocationRelativeTo(null);
f.setIconImage(icon);
f.setVisible(true);
g.start();
}
public void start() {
new Thread(this).start();
}
public void run() {
// updatin' 'n' stuff..
}
public void render() {
BufferStrategy bs = getBufferStrategy();
if (bs == null) {
createBufferStrategy(2);
return;
}
g = bs.getDrawGraphics();
Room.render(); // rendering the graphics with the use of g
g.dispose();
bs.show();
}
}
(Let me know if the code is not so relevant.)
I also have a class for handling key inputs by implementing KeyListener.
The question, what should I change in the code in order for it to be runnable in a browser?