问题
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