Java 图形用户界面问题

发布于 2024-11-09 13:08:03 字数 83 浏览 0 评论 0原文

因此,在我的项目中,我有一个交互式程序,要求用户输入值才能在控制台中获得响应。当用户输入程序将与之交互的响应时,如何使控制台出现在 GUI 的文本框中?

So in my project, I have an interactive program that requires the user to enter values to get a response in the console. How do I make it so that the console appears in a textbox in the GUI while the user enters responses that the program will interact with?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

空心空情空意 2024-11-16 13:08:03

一些建议:

  • 首先,确保您的程序是真正的 OOPS 程序,具有合适的类和最少的静态方法和成员。
  • 接下来确保您的用户界面和程序逻辑代码位于不同的类中。
  • 请注意,您将需要重新设计您的程序,因为您确实不想按照上面的要求尝试在 GUI 中运行类似控制台的程序,因为它违背了进行事件驱动 GUI 编程的目的。相反,创建一个像大多数 GUI 一样接受数据的 GUI,带有文本字段按钮等,用户可以选择与任何可供他交互的组件进行交互,而不是控制台程序的强制线性交互。
  • 最后阅读 Swing 教程以了解如何创建 Swing GUI。这就是全部了!

Some suggestions:

  • First of all, make sure that your program is a true OOPS program with decent classes and minimal static methods and members.
  • Next make sure that your user interface and program logic code are in separate classes.
  • Note that you'll want to redesign your program as you really don't want to try to run a console-like program in a GUI as you requested above since it defeats the purpose of doing event-driven GUI programming. Rather create a GUI that accepts data as most GUI's would, with text fields buttons and such, where the user can choose to interact with whatever component is available for him to interact with, rather than the forced linear interaction of a console program.
  • Lastly read the Swing tutorials to learn how to create Swing GUIs. That's all there is to it!
故笙诉离歌 2024-11-16 13:08:03

您可能想查看此链接(感谢 Google)

http://www .devdaily.com/java/java-exec-processbuilder-process-1

但本质上你需要:

  • 使用 Process p = Runtime.getRuntime().exec("") 运行命令,然后
  • 使用 p。 getInputStream() 来获取输出,您可以将其放在您喜欢的位置。

You might want to check out this link (thanks Google)

http://www.devdaily.com/java/java-exec-processbuilder-process-1

But essentially you need to:

  • use Process p = Runtime.getRuntime().exec("") to run a command then,
  • use p.getInputStream() to get the output and you can put this where you like.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文