Results 1 to 2 of 2
- 02-14-2008, 06:25 PM #1
Member
- Join Date
- Feb 2008
- Posts
- 1
- Rep Power
- 0
- 02-14-2008, 07:21 PM #2
Member
- Join Date
- Jan 2008
- Location
- South Africa
- Posts
- 18
- Rep Power
- 0
Is this via the console? If you want to register keystrokes, you will need to create a JFrame (Swing GUI), and then add a KeyListener, and then when the user presses a key, it will fire the "keyPressed" method, and from there you can catch the key pressed from the KeyEvent object which has been passed. You will need to read some JFrame/Swing tutorials, which explain Components, Listeners (Such as MouseListener and KeyListener) and you will also need to understand interfaces/inheritance (You implement or extend the KeyListener or KeyAdaptor).
Like:
JFrame frame = new JFrame();
frame.addKeyListener(this);
Then in the same class, you implement "KeyListener" and implement the abstract methods keyPressed(KeyEvent e), keyReleased(KeyEvent e), and keyTyped(KeyEvent e).
Then to get the keystroke, you call one of the methods of the KeyEvent e, such as:
char keychar = e.getKeyChar();
or
int keycode = e.getKeyCode();
-------------------------------
Hope that helps.
For full help, read this Swing Tutorial trail:
Trail: Creating a GUI with JFC/Swing (The Java™ Tutorials)
It explains all about Swing, and also look for the section on "Writing Event Listeners".
Similar Threads
-
Compiling a single class
By ROSOBORONEXPORTCORP in forum New To JavaReplies: 2Last Post: 01-28-2008, 12:27 PM -
convert a lot of images into a single one
By leonard in forum New To JavaReplies: 1Last Post: 08-06-2007, 04:47 PM -
variable to accept a single object
By Rgfirefly24 in forum New To JavaReplies: 1Last Post: 08-06-2007, 04:41 AM -
Help with import AWTKeyStroke and swing.KeyStroke
By susan in forum AWT / SwingReplies: 1Last Post: 07-29-2007, 10:53 PM -
File Upload - Single to allow the search of .txt files
By Daniel in forum Advanced JavaReplies: 1Last Post: 06-06-2007, 04:20 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks