简体   繁体   中英

How can I make an applet call and run another applet

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM