I currently have a small Java program which I would like to run both on the desktop (ie in a JFrame) and in an applet. Currently all of the drawing and logic are handled by a class extending Canvas. This gives me a very nice main method for the Desktop application:
public static void main(String[] args) { MyCanvas canvas = new MyCanvas(); JFrame frame = MyCanvas.frameCanvas(canvas); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); canvas.loop(); }
Can I do something similar for the applet? Ideally MyCanvas would remain the same for both cases.
Not sure if its important but I am drawing using BufferStrategy with setIgnoreRepaint(true).
Edit: To clarify, my issue seems to be painting the canvas — since all the painting is being done from the canvas.loop() call.
Applet is a Container, just add your Canvas there.