Java命令行中的键监听器 [英] Java key listener in Commandline

查看:323
本文介绍了Java命令行中的键监听器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大多数演示在Swing中显示keyevent,在命令行中是什么?

Most demo showing keyevent in Swing, what is the equivalent in commandline?

推荐答案

Swing与命令行环境因为您在控制台窗口中没有事件。标准GUI处理对象和事件。控制台没有这样的等效概念。

Swing is different from a command line environment in the sense that you have no events in a console window. A standard GUI deals with objects and events. A console has no such equivalent notion.

有一个标准输入(以及一个标准输出),你可以阅读。请参阅这个问题如何从控制台读取单个字符(不等待换行符) - 或者说,这是不是很容易在Java中做。

What you do have is a standard input (as well as a standard output), which you can read from. See this question on how to read a single char from console (without waiting for a newline) - or rather, on how this isn't very easy to do in Java.

当然,你可以在一个单独的线程上异步读取。即主线程将继续做东西,监听器线程等待I / O阻塞调用。但是这只能在应用程序级别上实现和处理。

Of course, you can always do the reading asynchronously on a separate thread. i.e. the main thread will keep doing stuff, with a listener thread waiting on the I/O blocking call. But this can only be implemented and handled on the application level.

这篇关于Java命令行中的键监听器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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