只有一个秋千框架窗口在时间打开 [英] only one swing frame window opened at time

查看:106
本文介绍了只有一个秋千框架窗口在时间打开的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发了一个swing应用程序,但每次运行应用程序时都会打开新窗口。
我希望如果一个窗口已经打开,其他窗口不允许打开。

I developed one swing application but each time you run application new window is opened. I want that if one window is already opened other not allow to open.

推荐答案

这里 Java单一应用程序实例的示例:


单实例应用程序是一个只允许运行1个应用程序的应用程序,无论用户尝试启动多少次。

A single instance application is one that only allows for 1 of the application to run no matter how many times the user tries to launch.

应用程序尝试在特定端口上打开Socket。如果你的应用程序的另一个实例已经运行,打开Socket会失败。

The application tries to open a Socket on a specific port. In case another instance of your application is already running, opening the Socket fails.

这应该已经足够了,所以你不必使用用于将新应用程序注册到第一个应用程序的代码。

This should already be sufficient for you, so you would not have to use the part of the code used to register new applications to the first one started.

与向文件系统/注册表/无论如何写一些标记相比,使用Socket有一个很大的优势: br>
即使您的应用程序崩溃,它也会被删除。

Using a Socket has one great advantage compared to writing some sort of flag to the filesystem/registry/whatever:
It is removed even if your application crashes.

这篇关于只有一个秋千框架窗口在时间打开的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆