Java JApplet to JFrame

一个人想着一个人 提交于 2019-12-01 12:35:19

Following a very basic example...

import javax.swing.JApplet;
import javax.swing.JButton;
import javax.swing.JFrame;


public class MyWordGame extends JApplet {

    public void init(){
        add(new JButton("Test"));
    }

    /**
     * @param args
     */
    public static void main(String[] args) {
        MyWordGame game=new MyWordGame();
        JFrame myFrame=new JFrame("Test");
        myFrame.add(game);
        myFrame.pack();
        myFrame.setVisible(true);
        game.init();

    }

}

You can run it both as applet or application. But remember that, if your applet interacts with browser, you must provide a custom AppletContext and you may also want to eventually provide a kind of management of applet's lifecycle (like calling start() / stop() / destroy() when appropriate).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!