Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Referring to JavaDoc, <code>KeyListener</code> methods have the following syntax: </p> <p><code>void keyPressed(KeyEvent e)</code><br> <code>void keyReleased(KeyEvent e)</code><br> <code>void keyTyped(KeyEvent e)</code> </p> <p>Going over your code, your syntax are:<br> <code>public void keyPressed(int i, char c)</code><br> <code>public void keyReleased(int i, char c)</code> </p> <p>This will be flagged as an error at compilation time. </p> <p>Also, you should, <em>ideally</em>, create a separate handler class for your events.<br> <code>TextField</code> is the object that will <em>generate</em> the event and there must be someone to listen to it. You need to specify who will listen by calling the <code>addKeyListener()</code> method and passing the handler class' object as an argument. </p> <p><em>PS: Switch to Swing. Use JTextField instead</em></p> <p>Refer: <a href="http://docs.oracle.com/javase/6/docs/api/java/awt/event/KeyListener.html" rel="nofollow noreferrer">http://docs.oracle.com/javase/6/docs/api/java/awt/event/KeyListener.html</a><br> Tutorial: <a href="http://docs.oracle.com/javase/tutorial/uiswing/events/keylistener.html" rel="nofollow noreferrer">http://docs.oracle.com/javase/tutorial/uiswing/events/keylistener.html</a><br> Event delegation model: <a href="http://wiki.answers.com/Q/What_is_delegation_event_model_in_java" rel="nofollow noreferrer">http://wiki.answers.com/Q/What_is_delegation_event_model_in_java</a><br> Advantages of swing: <a href="https://softwareengineering.stackexchange.com/questions/112482/advantage-of-using-swing-over-awt">https://softwareengineering.stackexchange.com/questions/112482/advantage-of-using-swing-over-awt</a></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload