如何将数据从另一个JFrame传输到另一个JFrame? [英] How to get data from other JFrame to another JFrame?

查看:86
本文介绍了如何将数据从另一个JFrame传输到另一个JFrame?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

成功登录后如何获得相同的名字?

How do I get the same name after a successful login?

我具有在登录 JFrame user.getName 中验证文本文件中的用户名和密码后,设置了 user.setName 的用户类.在其他框架中以在主菜单中与用户打招呼.

I have user class that set user.setName after verifying the user name and password from text file in login JFrame and user.getName in other frame to greet user in the main menu.

推荐答案

有很多不同的方法,但是基本上可以归结为

There's lots of different ways to do it, but basically it boils down to Passing Information to a Method or a Constructor.

您应该做的一件事就是尝试使过程脱钩.您的主菜单"并不关心在何处或如何生成/获得用户名,只需要它.同样,您的登录过程并不关心在验证用户之后会发生什么.

One thing you should do is to try and decouple the process. Your "main menu" doesn't care where or how the user name is generated/gained, it only needs it. Equally, your login process doesn't care what happens after the user is validated.

为此,您应该花些时间了解 model-view-控制器范例,您会看到很多,并会帮助您解决类似的问题.

To that end, you should take the time to understand the model-view-controller paradigm, you will see it a lot and will help you solve similar questions.

基本上,控制器"将显示登录视图,登录视图将收集凭据,并且此信息将通过模型反馈以进行验证.成功后,控制器可以将控制权传递给下一个控制器,该控制器将实际显示主菜单",并提供登录模型作为信息的一部分.

Basically, a "controller" will display the login view, the login view will gather the credentials and the this information will be feed back through the model for validation. When successful, the controller can pass control on to the next controller which will actually display the "main menu", providing the login model as part of the information.

同样,如何"在很大程度上取决于整体解决方案,但是您想要达到可以更改主菜单和登录窗口中的一个或两个的能力,并且这不会对主菜单和登录窗口产生任何影响.其他

Again the "how" depends a lot on the overall solution, but you want to get to the point where you have the ability to change either or both the main menu and login windows and it won't have any affect on the other

您也可以看看:

了解更多详细信息和想法

for more details and ideas

这篇关于如何将数据从另一个JFrame传输到另一个JFrame?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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