在一个Applet绘画画布 [英] Painting a Canvas in an Applet
问题描述
目前,我有,我想在桌面上(即在一个JFrame)上,并在小程序同时运行一个小型的Java程序。目前,所有的绘图和逻辑都通过扩展画布类处理。这给了我一个非常好的主要方法桌面应用程序:
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();
}
我可以做的小程序类似的东西?理想情况下MyCanvas将保持不变两种情况。
Can I do something similar for the applet? Ideally MyCanvas would remain the same for both cases.
不知道它的重要,但我使用BufferStrategy中以 setIgnoreRepaint图(真)
。
Not sure if its important but I am drawing using BufferStrategy with setIgnoreRepaint(true)
.
修改:为了澄清,我的问题似乎是画在画布上 - 因为所有的绘画正在从 canvas.loop()来完成
调用。
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.
这篇关于在一个Applet绘画画布的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!