• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Keyboard listner

 
Devu Shah
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Hello,
Can anyone guide me how to add keyboard listener to application without having gui.
Basically I want this for shutting down server gracefully.
Right now I am using very bad method�. .i.e. Server is waiting for user�s input in while loop. I don�t think this is right way . I think we could add simply keyboard listener. But how I don�t know?
Requesting for guideline.

Thanks
Devu
 
Michael Ernest
High Plains Drifter
Sheriff
Posts: 7292
Netbeans IDE VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Devu -
The way you're doing it now is not only honorable, it's the least overhead needed to get the job done. It may not seem like "pure OO," but in fact you should do it this way if you can.
Setting up a key listener is intended as a way to bind actions in the GUI to keyboard activity. And while it seems appealing to extend this mechanism elsewhere, the primary benefit seems to be intellectual satisfaction; the overhead of doing it without a GUI is not much different from doing it with a simple GUI visible.
------------------
Michael Ernest, co-author of: The Complete Java 2 Certification Study Guide
 
Devu Shah
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanx Michael Ernest for reply.
But i am not understanding two things.
1. How my way is good ? will it not keep one thread(?) waiting for users input? then will it not decrease server efficiency ?
2. Why BUT WHY there is no built in method in RMI for shutting down ?
And lastly if u dont mind can u guide me , if at all, i want to capture key events (like making hotkey ) in non gui Application,
how to do ? (because 'enableEvent' is for gui only )
thanks in advance.
regards
devu

 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic