简体   繁体   English

如何最大化Java Swing应用程序

[英]How to maximize java swing application

I have created a login page using java swing. 我已经使用Java swing创建了一个登录页面。 and i created jar for the application. 我为应用程序创建了jar。 Now when I run the jar then my login page is displayed then i minimize the application and again run the jar then another instance of my application is displayed (means now in my system I have two login page. 1 is in minimized format and another is in normal state. 现在,当我运行jar时,将显示我的登录页面,然后我将应用程序最小化,然后再次运行jar,然后将显示我的应用程序的另一个实例(意味着现在在我的系统中,我有两个登录页面。1是最小化格式,另一个是处于正常状态。

But I want that if in my system login page is already running and is minimized then if i run the jar once again then it will not start as a new application rather it should maximize the earlier login page. 但是我希望,如果我的系统登录页面已在运行并且已最小化,则如果我再次运行jar,则它将不会作为新应用程序启动,而应最大化先前的登录页面。

How to achieve this type of functionality ? 如何实现这种功能?

please help me 请帮我

Thanks Sunil Kumar Sahoo 感谢Sunil Kumar Sahoo

For a Web Start application, it's easy. 对于Web Start应用程序,这很容易。 You can use the SingleInstanceService and SingleInstanceListener classes. 您可以使用SingleInstanceService和SingleInstanceListener类。 You simply kill off the previous instance when the new instance is ran. 运行新实例后,您只需杀死前一个实例即可。

The previous instance should receive some message from the new one by implementing NewActivation(). 前一个实例应该通过实现NewActivation()从新实例中接收一些消息。 The previous instance should receive a shut down message and respond accordingly. 前一个实例应该收到关闭消息,并做出相应的响应。

The benefit of shutting down the previous instance is that it may have crashed, and bringing the new instance to the foreground is automatic. 关闭前一个实例的好处是它可能已崩溃,并且自动将新实例带到前台。

If you want to only have one instance of an application, open up a server socket at some unusual port if you get a failure then the app is already running so exit. 如果您只想拥有一个应用程序实例,则在出现故障时在某个不寻常的端口上打开服务器套接字,则该应用程序已在运行,请退出。

As far as your exact question, it is impossible for a Swing app to know about another one running without doing some specific code. 就您的确切问题而言,Swing应用程序如果不执行某些特定代码就不可能知道另一个正在运行的应用程序。

I guess you could use the Server Port of the app that is running actually listen and perform some commands. 我猜您可以使用正在运行的应用程序的服务器端口实际监听并执行一些命令。 The client app could then detect if the server port is unavailable, then open a client and send a command to the port. 然后,客户端应用程序可以检测服务器端口是否不可用,然后打开客户端并将命令发送到该端口。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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