How can I implement the press ANY key to continue in Java. In C I use getch() and it works fine but Java I must press enter in every read method implement in every OutputStream class.
Thanks in advance.
How can I implement the press ANY key to continue in Java. In C I use getch() and it works fine but Java I must press enter in every read method implement in every OutputStream class.
Thanks in advance.
The only way which I found was whith JNI and C.
I found a code, Equivalent function to C's “_getch()
I have given answer for this question Equivalent function to C's "_getch()" in Java? see my answer here
or use the code
public static void getCh() {
final JFrame frame = new JFrame();
synchronized (frame) {
frame.setUndecorated(true);
frame.getRootPane().setWindowDecorationStyle(JRootPane.FRAME);
frame.addKeyListener(new KeyListener() {
public void keyPressed(KeyEvent e) {
synchronized (frame) {
frame.setVisible(false);
frame.dispose();
frame.notify();
}
}
public void keyReleased(KeyEvent e) {
}
public void keyTyped(KeyEvent e) {
}
});
frame.setVisible(true);
try {
frame.wait();
} catch (InterruptedException e1) {
}
}
}