Java Applet 到多面板应用程序
我制作了一个Java游戏,但它是基于applet的。我想将其转换为独立的应用程序。不幸的是,我对 swing/java 应用程序一无所知,所以我不确定从哪里开始以及如何获得我想要的东西。
我的主要问题是游戏屏幕基本上分为两部分。 “游戏屏幕”和我所说的“仪表板”。如果您能想象《帝国时代》、《星际争霸》或任何其他 RTS 类型的游戏,那么布局就是这样的。
所以我想要的是屏幕有自己的图形面板(所有绘图/动画都是通过图形和图像类完成的),其中也有滚动条,这样游戏的大小就不受尺寸的限制您的屏幕。我希望仪表板成为它自己单独的独立面板,它也使用图形方法。但最终,两个面板都在同一个窗口中。
无论如何,这有可能吗?
PS:请随意索取游戏的任何代码或屏幕
截图编辑:如果可能的话,我应该如何去做呢?
I have made a Java game, but it is applet based. I want to convert it into a standalone application. Unfortunately I have 0 knowledge of swing/java applications so I'm not exactly sure where to start and how to get what I want.
My main issue is that the game screen is essentially divided into two parts. The "game screen" and what I refer to as the "dashboard". If you can imagine age of empires, star craft, or any other RTS type of game, that's what the layout is.
So what I want is the screen to have its own graphics panel (all the drawing/animation is done with the graphics and image class) that also has scroll bars in it, that way the size of the game isn't limited to the size of your screen. And I want the dashboard to be it's own separate independent panel, which also uses graphics methods. But in the end, both panels are in the same window.
Is there anyway this is possible?
PS: feel free to request any code or screenshots of the game
Edit: if it is possible, how should I go about doing this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
简单的 Swing 应用程序通常基于 JFrame 类。据我了解,整个游戏都是渲染的,并且没有在 UI 中使用标准组件。那么,粗略地说,
JApplet
和JFrame
类之间几乎没有区别。如果您使用特定的 JApplet 方法来加载资源或类似的方法,那么几乎所有这些方法都可以轻松地替换为对应的方法。您可以创建一个组件类(通过扩展
JComponent
)并使用它来渲染主游戏窗口。并创建另一个来渲染仪表板。然后使用BorderLayout
作为JFrame
上的布局管理器,将主窗口放置在中心,将仪表板放置在任意边缘。Oracle 网站上有非常清晰的 HowTo:
如何制作框架 和 如何使用面板。
Simple Swing applications usually based on
JFrame
class. As i understand, whole game is rendered and not using standard components in UI. Then, roughly, almost no difference betweenJApplet
andJFrame
classes. If you used specific JApplet methods for loading resources or something similar, almost all of them would easily replaced with counterparts.You could create a component class (by extending
JComponent
) and use it to render main game window. And create another one to render dashboard. Then useBorderLayout
as layout manager onJFrame
, place main window on center and dashboard on any edge.There are pretty clear HowTo`s on Oracle site:
How to Make Frames and How to Use Panels.
我认为 Mersenne 的答案很好地涵盖了这一点,尽管我会考虑在
BufferedImage
中渲染游戏并将其添加到JLabel<(中的
ImageIcon
) /code> 在JScrollPane
中。I think Mersenne's answer covers it pretty well, though I'd consider rendering the game play in a
BufferedImage
and adding that to (anImageIcon
in) aJLabel
in aJScrollPane
.