是否可以打印用户可以编辑的文本(对于控制台程序)?
假设我允许用户编辑某些内容,例如地址簿中的电话号码(实际上,这正是我正在做的事情)。我可以在 println 中添加一些内容,以允许我插入一个变量以显示为完全可编辑的文本吗?我正在做的任务实际上并不需要这样做,但我认为这样做会很酷。我正在谷歌上查找,但找不到任何东西,但我又不知道我在寻找什么,也不知道我是否记住了正确的条款......
Say I allow the user to edit something, like the phone number in an Address Book (actually, that's exactly what I'm doing). Is there something that I can add to println that will allow me to insert a variable to display as fully editable text? The assignment that I'm doing this for doesn't actually call for this, but I think it would be cool to have. I'm looking on Google but can't find anything, then again I don't really know what I'm looking for and whether or not I have the correct terms in mind ...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
不,不只是使用 Java 在框架中提供的内容。编辑某些文本需要
这可以完成使用一些本机代码(Linux 上的 ncurse,...),使用 JNI 或 JNA,但不是那么容易。
请注意,有些项目旨在添加这些功能,因此如果您可以使用核心库之外的功能,您可以尝试一下......例如 http://code.google.com/p/java-console-api/
No, not using only what Java provides in the framework. Editing some text would require to
This could be done using some native code (ncurse on linux, ...), using JNI or JNA, but not that easily.
Note that there are some projects that aim to add those functionalities, so if you can use something outside of the core libraries, you could give them a tries... for instance http://code.google.com/p/java-console-api/
按照功能和复杂性的简单性和可移植性的顺序,有多种选项:
简单地提示信息,读取完整的(返回终止的)响应行,并允许使用正常的终端输入设施基本编辑。
使用 gnu readline 库之类的东西来允许更高级的编辑。尽管如此,您仍然不会有小部件(屏幕上特定位置的文本输入框)。这里有一个java实现: http://java-readline.sourceforge.net/
使用 ncurses 之类的东西来专门定位光标、打印文本标签、处理按键以及实现您自己的文本输入框。不好玩。
使用文本用户界面库 (TUI),如下所示:http://www.bmsi。 com/tuipeer/
There are various options for this, in order of simplicity and portability to features and complexity:
Simply prompt for the information, reading a complete (return-terminated) line of response, and allow the normal terminal input facilities to be used for basic editing.
Use something like the gnu readline library to allow more advanced editing. You still won't have widgets (text input boxes at specific places on screen) as such though. There's a java implementation here: http://java-readline.sourceforge.net/
Use something like ncurses to specifically position the cursor, print text labels, handle keypresses, and implement your own text input box. Not fun.
Use a textual user interface library (TUI), like this one: http://www.bmsi.com/tuipeer/
如果您打开了一个看起来像控制台窗口的窗口,并且可以对按键事件做出反应,那么您可以执行您所要求的操作,但是,否则,如果您只是运行一个程序,该程序将停止执行并将控制返回给你的控制台,所以它不能做任何其他事情。
但是,如果您使用可编写脚本的 java 版本,您可以编写自己的 shell,然后您可以执行您所要求的操作,因为 shell 不会停止执行。
但是,这可能超出了你的课程范围。
If you opened a window that looks like the console window, and could react to keypress events, then you could do what you are asking, but, otherwise, if you are just running a program, the program will have ceased executing and returned control to your console, so it can't do anything else.
But, if you use a scriptable version of java you could write your own shell, and then you could do what you are asking, as the shell would not cease executing.
But, that will probably be beyond your course.