问题描述
我已经做了一个游戏作为一个小程序,但是我想在开始添加一个开始,关闭菜单。我在想,如果它可能使菜单单独的小程序,当启动时pressed,它会调用并运行其他小程序?
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?
推荐答案
首先,不这样做,这是不是真的你如何code应该工作。你的启动/关闭菜单应该是相同的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.
您可以使用类似 CardLayout
动摇的不同面板之间的意见交换。
You could use something like CardLayout
to vacillate the switching of the views between different panels.
这允许您使用 Applet的
简单地作为其他视图的容器和开关这些意见根据自己的规则和要求。看看
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
但是,从你似乎是在说什么,你所有你的逻辑已经直接$ C $光盘放入小程序本身,这是一个坏主意,因为你已经发现。
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)
有一个更好的解决方案可能会被利用来启动的JPanel
为你的主容器,适用 CardLayout
将其与有每个视图作为单独的组件。这是现在为您提供的额外的灵活性能够决定如何显示程序,小程序,框架或其他容器
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
这篇关于我怎样才能让一个小程序调用和运行其他小程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!