Results 1 to 12 of 12
- 03-28-2010, 12:22 AM #1
Member
- Join Date
- Mar 2010
- Posts
- 5
- Rep Power
- 0
Reading characters without showing up on the screen?
Hey guys,
I am trying to read a character in Java without having it show up on the screen. It is possible with the hsa class, but i absolutely hate ready to program, and I do not want to use it. Is there any way to do that with Standard Java libraries?
Thanks
-
Yes, this could be done in a Swing GUI, but if you don't know Swing, you have a bit to learn first before you can do this.
Welcome to the forum by the way.
- 03-28-2010, 12:36 AM #3
Member
- Join Date
- Mar 2010
- Posts
- 5
- Rep Power
- 0
Thanks Fubarable,
Would you recommend any examples or tutorials that have what I am looking for in them? I'm not a beginner programmer, i just think its a beginner question and thus i posted it here.
So there is no way to do this in the console? If not, what's the method called, and I'll look it up in the API.
*If people didn't understand what I'm talking about, I am looking for the Java equivalent of readkey from Pascal.*
-
I think what you're trying to do is to read in what the user is typing without displaying this anywhere, correct? If so, you'd need to give your Swing application a KeyListener on a component that has focus or an application-global listener (I believe that this would involve using an AWTEventListener but must admit that I've never used one). The best tutorials for Swing are the Sun tutorials. This and the API usually will get you going in the right direction.
- 03-28-2010, 01:35 AM #5
Member
- Join Date
- Mar 2010
- Posts
- 5
- Rep Power
- 0
Would this be what you are talking about?
KeyListener (Java 2 Platform SE v1.4.2)
There is also an example about it How to Write a Key Listener (The Java™ Tutorials > Creating a GUI With JFC/Swing > Writing Event Listeners)
-
- 03-28-2010, 04:18 AM #7
Member
- Join Date
- Mar 2010
- Posts
- 5
- Rep Power
- 0
So I would be looking for when KeyPressed would happen from here? KeyListener (Java Platform SE 6)
What exactly would be the difference between KeyPressed and KeyTyped?
-
Yep.
The API tells me to look into the KeyEvent API to learn the difference. There you'll find these constants:What exactly would be the difference between KeyPressed and KeyTyped?
KEY_TYPED: The "key typed" event. This event is generated when a character is entered. In the simplest case, it is produced by a single key press. Often, however, characters are produced by series of key presses, and the mapping from key pressed events to key typed events may be many-to-one or many-to-many.
KEY_PRESSED: The "key pressed" event. This event is generated when a key is pushed down.
- 03-28-2010, 04:31 AM #9
Senior Member
- Join Date
- Mar 2010
- Posts
- 953
- Rep Power
- 4
You'll want to read the link below, but basically keyTyped() is about characters and keyPressed() is about other keys (Shift, Ctrl, Alt, Function keys, arrow keys, etc.). That's a bit oversimplified, but it's a useful way to think about it.
KeyEvent (Java Platform SE 6)
-Gary-
- 03-28-2010, 08:02 AM #10
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,606
- Blog Entries
- 7
- Rep Power
- 17
- 03-28-2010, 07:34 PM #11
Member
- Join Date
- Mar 2010
- Posts
- 5
- Rep Power
- 0
- 03-28-2010, 08:08 PM #12
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,606
- Blog Entries
- 7
- Rep Power
- 17
I was thinking of the readPassword() method (read the API documentation) but you seem to want instantaneous response after pressing a single key. A Console can't do that; you either have to use Swing as other repliers have pointed out or you have to use a third party library or use JNI for that purpose.
kind regards,
Jos
Similar Threads
-
problem with reading excel sheet data reading using poi libraries
By sandeepsai17 in forum New To JavaReplies: 5Last Post: 08-21-2009, 11:03 AM -
Blank Screen while navigating from one screen to another
By mohana.krishna in forum Java ServletReplies: 0Last Post: 03-03-2009, 05:03 PM -
writing and reading unicode characters from a file
By ranoosh in forum Advanced JavaReplies: 4Last Post: 09-28-2008, 04:34 AM -
Showing
By bostonstate in forum New To JavaReplies: 3Last Post: 08-25-2008, 07:49 PM -
Why isn't this showing?
By JToolTip in forum Java AppletsReplies: 2Last Post: 07-07-2007, 11:54 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks