Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to solve "Keystrokes is not abstract and does not override ab. method"
    primarykey
    data
    text
    <p>I am a learning Java programming and am trying to compile the below code from a book. When I try to compile the code I get this error </p> <pre><code>Keystrokes is not abstract and does not override abstract method keyTyped (java.awt.event.KeyEvent) in java.awt.event.KeyListener. </code></pre> <p>Also, I believe this is unrelated but the book also told me to add this section of code to the source code(somewhere?):</p> <pre><code>pnl.add ( field) ; pnl.add (txtArea); </code></pre> <p>When I do I get an Identifier "Expected Error".</p> <p>The program code:</p> <pre><code>import javax.swing.*; import java.awt.event.*; class Keystrokes extends JFrame implements KeyListener { JPanel pnl = new JPanel(); public static void main (String[ ] args){ Keystrokes gui = new Keystrokes(); } JTextField field = new JTextField ( 38 ); JTextArea txtArea = new JTextArea (5, 38); public Keystrokes() { super( "Swing window"); setSize( 500,200); setDefaultCloseOperation( EXIT_ON_CLOSE ); add(pnl); field.addKeyListener (this ); setVisible( true ); } public void keyPressed(KeyEvent event ) { txtArea.setText("Key Pressed"); throw new UnsupportedOperationException("Not supported yet."); } public void KeyTyped (KeyEvent event ) { throw new UnsupportedOperationException("Not supported yet."); txtArea.append("\nCharacter : " + event.getKeyChar() ); } public void keyReleased ( KeyEvent event) { int keyCode = event.getKeyCode(); txtArea.append("\nKey Code : " + event.getKeyCode() ); textArea.append("\nKey Text : " + event.getKeyText(keyCode)); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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