Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8432849
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T06:13:50+00:00 2026-06-10T06:13:50+00:00

java: I’m stuck on the error The type Pong.Move1 must implement the inherited abstract

  • 0

java: I’m stuck on the error The type Pong.Move1 must implement the inherited abstract method
KeyListener.keyTyped(KeyEvent)
when I used keyListener. I don’t get what it means? Help?

Here’s the Thread I’m having trouble on…

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){

}

}

I’m also stuck on the Thread.sleep(500); line I have. It says Unhandled exception type InterruptedException. Any help? Thx.

Oh, I forgot something.
1:When I try to run it, the only error I get is:
Exception in thread "main" java.lang.Error: Unresolved compilation problem: at Pong.main(Pong.java:50). That’s the public static void main(String[] args) line. My complete code is at the end so you can look at it (plz)
2:I’m using eclipse.
3:I am basically a beginner (not really)

My complete 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...
 */
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T06:13:52+00:00Added an answer on June 10, 2026 at 6:13 am

    In order to implement KeyListener, you need to implement all of the methods that that individual interface contains.
    These are:

    keyPressed
    keyDown
    keyTyped
    

    In order to use interfaces you must implement all of their methods.

    Also, Thread.sleep(500) might generate an exception. Java is basically requiring you to handle an error just in case something goes wrong. To do this, you need a try…catch, like so:

    try
    {
        Thread.sleep(500);
    }
    catch(InterruptedException e)
    {
        System.out.println("Error!");
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Java doesn't support multiple inheritance for abstract classes, but I'm trying to do the
java BufferReader has a method readLine which reads till '\n' or '\r' is read
java.sql.SQLException: Network error IOException: Connection timed out: connect at net.sourceforge.jtds.jdbc.ConnectionJDBC2.(ConnectionJDBC2.java:410) at net.sourceforge.jtds.jdbc.ConnectionJDBC3.(ConnectionJDBC3.java:50) at net.sourceforge.jtds.jdbc.Driver.connect(Driver.java:184)
java.io.WriteAbortedException: writing aborted; java.io.NotSerializableException Why am I getting this error while starting my server
java.util.TimeZone.getTimeZone(id) is a method to obtain a timezone based on an id. While I
Java has a convenient split method: String str = The quick brown fox; String[]
Java is nearing version 7. It occurs to me that there must be plenty
Java - I have a abstract base class and I want to set few
Java generics are implemented using type erasure. That means that if I have a
Java DataInputStream class method readFully is used for reading the bytes from the stream

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.