0
Keyboard
How can I set the value of a variable via keyboard while the program is running ? :/
6 Respostas
+ 3
For better interactivity you can have a look at:
keyPressed() ,
keyTyped(),
and keyReleased()
event listeners:
https://docs.oracle.com/javase/7/docs/api/java/awt/event/KeyListener.html
tutorial is here:
https://docs.oracle.com/javase/tutorial/uiswing/events/keylistener.html
Simplier option:
Processing IDE: you only have to write a keyPressed/released/typed function as the processing library handles the nitty gritty for you. and all info with contestual examples are available in the reference. https://processing.org
+ 2
after you add the keylistener to an element of your program(Jframe, JtextField, image ecc...)
element.addKeyListener(this);
you can define your own function wherever inside the main.
public void keyTyped(KeyEvent e) {
displayInfo(e, "KEY TYPED: ");//replace with your code
}
+ 1
Use Scanner x=new Scanner(System.in) or InputstreamReader...?
0
can you please give me an example of the command and where should be written?
0
Thanks a lot I will give it a try and I will inform you if I face any problem with it