Note that there are some explanatory texts on larger screens.

plurals
  1. POThe type [classname] must implement the inherited abstract method KeyListener.keyTyped(KeyEvent)
    primarykey
    data
    text
    <p><p>java: I'm stuck on the error <b>The type Pong.Move1 must implement the inherited abstract method KeyListener.keyTyped(KeyEvent)</b> when I used keyListener. I don't get what it means? Help?<p>Here's the Thread I'm having trouble on...</p> <pre><code>private class Move1 extends Thread implements KeyListener{ public void run(){ addKeyListener(this); while(true){ //hitRight makes you lose. //point is how many times it ricochets. if(ball.intersects(borderRight)){ hitRight = true; } if(ball.intersects(borderLeft)){ point++; } } } public void keyPressed(KeyEvent event){ while(event.getKeyCode()==40||event.getKeyCode()=='s'){ direction = DOWN; Thread.sleep(500); } } public void KeyReleased(KeyEvent event){ } public void KeyTyped(KeyEvent event){ } } </code></pre> <p><p>I'm also stuck on the <code>Thread.sleep(500);</code> line I have. It says <b>Unhandled exception type InterruptedException</b>. Any help? Thx. <p>Oh, I forgot something.<br /> 1:When I try to run it, the <b>only</b> error I get is:<br /> <code>Exception in thread "main" java.lang.Error: Unresolved compilation problem: at Pong.main(Pong.java:50)</code>. That's the <code>public static void main(String[] args)</code> line. My complete code is at the end so you can look at it (plz)<br /> 2:I'm using eclipse.<br /> 3:I am basically a beginner (not really)<br /> <p>My complete code:<br /></p> <pre><code>import java.awt.*; import javax.swing.*; import javax.swing.event.*; import java.awt.event.*; import javax.swing.JFrame; import javax.swing.JTextField; import javax.swing.event.EventListenerList; public class Pong extends JFrame{ public final int WIDTH = 1000, HEIGHT = 1000; final int UP = 1, DOWN = 2; boolean hitRight; int point = 0; int direction; Rectangle bg = new Rectangle(0,0,WIDTH,HEIGHT); Rectangle borderLeft = new Rectangle(0,0,WIDTH/320,HEIGHT); Rectangle borderRight = new Rectangle(WIDTH-WIDTH/320,0,WIDTH/320,HEIGHT); Rectangle borderTop = new Rectangle(borderLeft.x,borderLeft.y,WIDTH,HEIGHT/35); Rectangle borderBottom = new Rectangle(0,HEIGHT-HEIGHT/320,WIDTH,HEIGHT/320); Rectangle ball = new Rectangle(WIDTH/2,HEIGHT/2,WIDTH/64,HEIGHT/64); Rectangle board = new Rectangle(WIDTH-WIDTH/160,0,WIDTH/128,HEIGHT/10); public void paint(Graphics graphics){ super.paint(graphics); graphics.setColor(Color.BLACK); graphics.fillRect(bg.x,bg.y,bg.width,bg.height); graphics.setColor(Color.RED); graphics.fillRect(borderLeft.x, borderLeft.y, borderLeft.width, borderLeft.height); graphics.fillRect(borderRight.x, borderRight.y, borderRight.width, borderRight.height); graphics.fillRect(borderTop.x, borderTop.y, borderTop.width, borderTop.height); graphics.fillRect(borderBottom.x, borderBottom.y, borderBottom.width, borderBottom.height); graphics.setColor(Color.WHITE); graphics.fillRect(ball.x,ball.y,ball.width,ball.height); graphics.fillRect(board.x,board.y,board.width,board.height); } /** * This Pong game made by me. * This has no copied code. * Any similarities are coincidences. * @param args */ /* * The constructor. */ public Pong(){ super("Pong"); setSize(WIDTH, HEIGHT); setVisible(true); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } public static void main(String[] args) { // TODO Auto-generated method stub Pong p = new Pong(); } /* * The move thread. */ private class Move1 extends Thread implements KeyListener{ public void run(){ addKeyListener(this); while(true){ //hitRight makes you lose. //point is how many times it ricochets. if(ball.intersects(borderRight)){ hitRight = true; } if(ball.intersects(borderLeft)){ point++; } } } public void keyPressed(KeyEvent event){ while(event.getKeyCode()==40||event.getKeyCode()=='s'){ direction = DOWN; Thread.sleep(500); } } public void KeyReleased(KeyEvent event){ } public void KeyTyped(KeyEvent event){ } } } /* * End of move thread... */ </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.
 

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