How can I make an applet call and run another applet

懵懂的女人 提交于 2020-03-26 06:58:04

问题


I have made a game as an applet however I want to add a "start" "close" menu at the beginning. I was wondering if its possible to make the menu as a separate applet and when "start" is pressed, it will call and run the other applet?


回答1:


First of all, don't, this isn't really how you code should work. Your start/close menus should be within the same applet context/container.

You could use something like CardLayout to vacillate the switching of the views between different panels.

This allows you to use the Applet simply as a container for other views and switch those views based on your own rules and requirements. Take a look at How to Use CardLayout for more details

But from what you seem to be saying, you've coded all you logic directly into the applet itself, which is a bad idea, as you've discovered.

Secondly, given the fact that most browsers are now days actively blocking applets, it doesn't really make a lot of sense to continue using them (and the added complexity in there management make them unappealing)

A better solution might to start by using a JPanel as you primary container, apply a CardLayout to it and having each view as separate components. This now provides you the added flexibility of been able to decide how to display the program, applet, frame or other container



来源:https://stackoverflow.com/questions/32685555/how-can-i-make-an-applet-call-and-run-another-applet

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