如何实现CMD+ Java 中的 N (OS X)
我正在为 OSX 编写第一个 Java 应用程序。
您可能知道 OSX 中应用程序的处理与 Windows 略有不同。 在 Windows 1 中,JFrame 通常意味着这是应用程序的一个实例,因此如果我想关闭整个应用程序,我只需关闭窗口即可。
在 OSX 中,窗口和应用程序是两个独立的东西。当您关闭窗口时,应用程序将在后台继续运行。
我想要做什么:
- 当用户点击 CMD + NI 想要创建我的类应用程序的新实例时,
是否有类似的最佳实践?当没有活动窗口时,谁必须听 Key-Stroke 的声音? main 是在哪个类中实现的?
I'm writing one of my first Java-Applications for OSX.
As you might know the handling of applications in OSX differs a little bit from Windows.
In windows 1 JFrame normaly means that this is one instance of the application, so if I want to close the whole application I just close the window.
In OSX the windows and the application are 2 seperate things. When you close the window an application keeps running in the background.
What I want to do:
- When the user hits CMD + N I want to create a new Instance of my class Application
Is there something like a best practise for this? Who has to listen to Key-Stroke's when there is no active window? The class where main is implemented?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
没有理由在 Windows 和 OSX 上有不同的情况。如果您实现 Windows 所谓的多文档界面 (MDI),那么它在 OSX 上的工作方式与在 Windows 上的工作方式完全相同。它们看起来有些不同,但在概念上它们是相同的。在这两种情况下,都有一个菜单栏(Application 类)控制零个或多个文档窗口(JFrame 实例)。
因此,您有一个创建单个应用程序的主类,它创建菜单栏并开始侦听击键,它还可能创建一个初始窗口,具体取决于您的应用程序规则。一旦运行,您可以监听 CMD-N 来创建新的 JFrame。
顺便说一句,在 Windows 中,1 个 JFrame 可能意味着一个单独的实例,但并不总是意味着这个意思。考虑 Internet Explorer 创建新窗口实例的方式 - 如果您使用 Cntl-N 创建新窗口,它会与父窗口共享会话和其他资源,也就是说,它不是单独的,而只是另一个文档。同时,您可以从开始菜单启动另一个 IE 实例,它不会与其他两个正在运行的 IE 窗口共享会话或资源。然而,这三个在任务栏中看起来像是完全独立的应用程序。
There is no reason to have this different on Windows and OSX. If you implement what Windows calls Multiple Document Interface (MDI) it works exactly the same on OSX as it does on Windows. They will look a little different, but conceptually they are identical. In both cases, there is a menu bar (Application class) that controls zero or more document windows (a JFrame instance).
So you have a main class that creates a single Application, which creates your menu bar and begins listening for key strokes, it may also create an initial window, depending upon your application rules. Once it is running, you can listen for CMD-N to create new JFrame.
As an aside, in Windows, 1 JFrame can mean a seperate instance, but it doesn't always have to mean that. Consider the way Internet Explorer creates new window instances -- if you use Cntl-N to create a new window, it shares session and other resources with the parent window, that is, it is not seperate, but just another document. At the same time, you can launch another IE instance from your start menu and it will NOT share session or resources with the other two running IE windows. Yet all three look like fully separate applications in the task bar.