简体   繁体   English

从一类的文本字段中获取输入,然后在另一类中进行扫描

[英]Taking input from a text field in one class and scanning it in a different class

I am trying to make a GUI for a program I have completed and do not want to modify. 我正在尝试为已完成但不想修改的程序制作GUI。 My problem is the program uses a scanner to get user input and I don't know how to get input from the GUI to the scanner. 我的问题是程序使用扫描仪获取用户输入,但我不知道如何从GUI向扫描仪获取输入。 I know how to use getText() from a text field in the GUI but that doesn't update the scanner so the main program just waits for that input and doesn't continue. 我知道如何从GUI的文本字段中使用getText(),但这不会更新扫描程序,因此主程序只是等待该输入而不会继续。

"I am trying to make a GUI for a program I have completed and do not want to modify." “我正在尝试为已完成但不想修改的程序制作GUI。”

When you give restrictions such as this, it is usually a good idea to explain more, such as the reasons for the restriction; 当您给出这样的限制时,通常最好多解释一下,例如限制的原因。 this understanding often helps us give better answers. 这种理解通常可以帮助我们给出更好的答案。

"My problem is the program uses a scanner to get user input and I don't know how to get input from the GUI to the scanner. I know how to use getText() from a text field in the GUI but that doesn't update the scanner so the main program just waits for that input and doesn't continue." “我的问题是程序使用扫描仪获取用户输入,但我不知道如何从GUI向扫描仪获取输入。我知道如何在GUI的文本字段中使用getText(),但这并不更新扫描仪,以便主程序仅等待该输入,而不会继续。”

You are trying to do what is next to impossible. 您正在尝试做几乎不可能的事情。 The solution: correct your console class so that the user interface portion is separated out, a la MVC, so that the model can be used for either a console program or a GUI program. 解决方案:修改控制台类,以便将用户界面部分(例如MVC)分离出来,以便该模型可用于控制台程序或GUI程序。

So the simple answer is: don't try to do this. 因此,简单的答案是:不要尝试这样做。 Create a well behaved set of classes with decent separation of concerns so that you can re-use classes well. 创建具有良好关注点分离的行为良好的类集,以便您可以很好地重用类。

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

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