关闭当前表单并打开新表单,然后将参数从已关闭的表单传递给新表单 [英] Close Current Form and open new one and passing a parameter from the closed form to the new one

查看:89
本文介绍了关闭当前表单并打开新表单,然后将参数从已关闭的表单传递给新表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

请任何人告诉我如何关闭当前表单并打开新表单.我在开始时有一个登录表单,当登录成功时,我想打开一个新表单,并传递用户用来登录新表单的ID,那么我该如何在Java中进行此操作?

在此先谢谢您!!

Hi all ,

Please can anyone tell me how to close current form and open new one.? I have a login form at the beginning and when it is successful i want to open a new form passing the id that the user used to login to the new form so how can i do this in java ?

Thanks in advance.!

推荐答案

嗨.

这在帖子中不容易解释,但我会试一试.

您没有指定是否使用Swing,AWT,SWT或其他任何工具.我将尝试以一般的方式进行解释,我只做了一些SWT.

您应该有一个模型,该模型封装了您希望在表单之间传递的数据.例如,一个"User"类.此类将包含用户名,登录是否成功以及要保留在其中的任何数据.

您的登录表单(例如类LoginWindow)应具有User实例的吸气剂.现在,要将User实例传递给第二种形式,您可以通过其构造函数,setter来实现,或者也可以使User类成为单例(http://en.wikipedia.org/wiki/Singleton_pattern [ ^ ]).

实现您所追求的目标的方法有很多,我正在展示至少一种方法.

希望对您有帮助.
Hi.

This is not something easy to explain in a post, but I''ll give it a shot.

You don''t specify whether you''re using Swing, AWT, SWT, or whatever. I''ll try to explain it in some general way, I have only done some SWT.

You should have a model, which encapsulates the data that you want to pass around between the forms. For example, a "User" class. This class would contain the username, whether login was successful, and any data that you want to keep in it.

Your log-in form, say class LoginWindow, should have a getter for the User instance. Now, to pass the User instance to the second form, you could do it through it''s constructor, a setter, or maybe you could make the User class a singleton (http://en.wikipedia.org/wiki/Singleton_pattern[^]).

There are many ways to achieve what you''re after, I''m showing at least one.

Hope this helps you.


这篇关于关闭当前表单并打开新表单,然后将参数从已关闭的表单传递给新表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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