This week's book giveaway is in the Mac OS forum. We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line! See this thread for details.
Hi all, I'm working on some program that should read any number, of course to some limit i know, and based on it do some operation. Well I should enter this number from the keyboard without a textField or anything else. i.e. i should just when i press on any number ,for example number 20, and press Enter I want to store that value for later use. How can i do that?
I think he wants to use keylistener for it... so then for your class name you have Classname implements KeyListener and then you must include the methods public void keyPressed(keyEvent e) public void keyTyped(KeyEvent e) public void keyReleased(KeyEvent e) The methods can all be blank except keyTyped if you just want to read the key, so in keyTyped you could do e.getKeyCode() which would tell you which key was pressed. If the key pressed was a number, then you could store it into an array. And if the key pressed was enter, it could proccess what was stored in the array. As for how to check if they key pressed was a number, I think you can find the different variable constants at the sun java class listing. Here's an example of using keyPressed in one of my progs:
Can anyone confirm if I'm right or not? I want to help other people but I think maybe I should stick to being helped . [ July 07, 2003: Message edited by: Matt Fyffe ]
Joined: Jul 01, 2003
hi Fyffe, your answer was really perfect.. u r absolutly right.. well i'm now using it in my program and its working perfect.. good luck Matt Ola