功能相当于C中的&​​QUOT; _getch()"在Java中? [英] Equivalent function to C's "_getch()" in Java?

查看:202
本文介绍了功能相当于C中的&​​QUOT; _getch()"在Java中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是用C / C乱搞++和最近发现的的_getch()功能。我最近还得到了一个邀请谷歌Wave(惊人的,顺便说一句),我想效仿发送消息的能力,你竟然打回车键之前。但是,我不知道多少(什么<&LT)。关于C / C ++的网络,虽然我知道在Java中关于它的体面的数额

I was messing around with C/C++ and recently found the _getch() function. I also recently got an invite to Google Wave (amazing, btw), and I wanted to emulate the ability to send messages before you actually hit the enter key. However, I don't know much (anything <.<) about networking in C/C++, while I know a decent amount about it in Java.

点:
是否有一个Java等同于C函数 _getch()

谢谢,
流行

推荐答案

我发现了一个code,功能相当于C中的_getch()

I found a code, Equivalent function to C's "_getch()


public static void getCh() {  
        final JFrame frame = new JFrame();  
        synchronized (frame) {  
            frame.setUndecorated(true);  
            frame.getRootPane().setWindowDecorationStyle(JRootPane.FRAME);  
            frame.addKeyListener(new KeyListener() {
                @Override 
                public void keyPressed(KeyEvent e) {  
                    synchronized (frame) {  
                        frame.setVisible(false);  
                        frame.dispose();  
                        frame.notify();  
                    }  
                }  
                @Override 
                public void keyReleased(KeyEvent e) {  
                }  
                @Override 
                public void keyTyped(KeyEvent e) {  
                }  
            });  
            frame.setVisible(true);  
            try {  
                frame.wait();  
            } catch (InterruptedException e1) {  
            }  
        }  
    }

这篇关于功能相当于C中的&​​QUOT; _getch()&QUOT;在Java中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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