JFrame 打开 JApplet
我正在用 java 编写一个程序,其中 JFrame 中的 JButton 将隐藏 JFrame 并运行 JApplet
我做了类似的事情,
OpenButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e){
hide();
JApplet startGame = new MainApplet();
startGame.init();
startGame.start();
}
});
我做错了什么?谢谢
I am making a program in java which the JButton in JFrame will hide the JFrame and run a JApplet
I have done something like
OpenButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e){
hide();
JApplet startGame = new MainApplet();
startGame.init();
startGame.start();
}
});
what am I doing wrong? thank you
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为您正在寻找的解决方案是主逻辑和顶级容器 JFrame 和 JApplet 的单独类。
然后您可以在单击按钮时启动游戏窗口而不是 GameApplet。如果您已经在小程序或窗口内运行,则无需创建单独的 GameApplet 和 GamePanel 类。您可以将 GamePanel 添加到您想要的任何容器中。
I think the solution you are looking for is a separate class for the main logic and top level containers JFrame and JApplet.
Then you can launch the game window instead of GameApplet on button click. If you are already running inside an applet or a window, you don't need to create separate GameApplet and GamePanel classes. You can just add the GamePanel to whichever container you want.