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 7997717
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T15:01:38+00:00 2026-06-04T15:01:38+00:00

I only studied till methods and am not patient enough to wait till my

  • 0

I only studied till methods and am not patient enough to wait till my UNI teaches me the rest so i found this interesting… I want to create a GUI with a circle in the middle that moves according to what button you press with java. after alot of reading i managed to get it done this way. So before i got to the error mentioned in the question i had 19 errors and only when i figured all of them out this error suddenly appeared. I hope i don’t tick anybody’s nerve cause am sure this mistake is due to some lack of programming foundation.
any help will be very much appreciated. I pointed out where the error occured by “<—”

import java.awt.*;
import java.awt.event.*;
public class Move_the_ball extends Frame {

public static void main(String[] args) {
    Move_the_ball me = new Move_the_ball();
    me.setVisible(true);
}
public Move_the_ball(){
    setSize(700,700);
    setLocation(100,100);
    setTitle("Moving the ball");
    setLayout(new BorderLayout());
    Panel buttonPanel = new Panel();
    buttonPanel.setBackground(Color.blue);
    buttonPanel.setLayout(new FlowLayout());

    Button goUp = new Button("Go up");
    goUp.addActionListener(this); <-----------------
    buttonPanel.add(goUp);

    Button goDown = new Button("Go down");
    goDown.addActionListener(this); <--------------
    buttonPanel.add(goDown);


    Button turnRight = new Button("Turn right");
    turnRight.addActionListener(this);  <-------------
    buttonPanel.add(turnRight);


    Button turnLeft = new Button("Turn left");
    turnLeft.addActionListener(this); <---------------
    buttonPanel.add(turnLeft);
}
    public void paint(Graphics g)
        {
        g.fillOval(x,y,h,d);
}
    private int x=200;
    private int y=100;
    private int h=50;
    private int d=50;

    public void actionPerformed (ActionEvent e){
        String actionCommand = e.getActionCommand();
        if(actionCommand.equals("Go up"))
        {
            y=y-5;
            repaint();
        } else if (actionCommand.equals("Go down"))
        {
            y=y+5;
            repaint();
        } else if (actionCommand.equals("Turn right"))
        {
            x=x+5;
            repaint();
        } else if (actionCommand.equals("Turn left"));
        {
            x=x-5;
            repaint();
        }
    } 
 }
  • 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-04T15:01:40+00:00Added an answer on June 4, 2026 at 3:01 pm

    Your Move_the_ball class must implement java.awt.event.ActionListener interface for this to work.

    import java.awt.*;
    import java.awt.event.*;
    public class Move_the_ball extends Frame implements ActionListener {
    
       public void actionPerformed(ActionEvent e) {
          // handle the e event
       }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Static methods may not communicate with instance fields, only static fields. I got to
Only one instance of a ScriptManager can be added to the page. this error
I only get this warning if I import my helper class (#import JLHelper.h). An
I only want to show my title attribute in some cases. I don't want
I studied the Twitter API Documentation today. Only find that we could use Twitter
I only very recently began developing professionally. I studied OOP while at University, but
Till now I haven't really studied secure communication and I have some basic questions.
Having studied the switch documentation and discovering it can only switch on integral types
As many programmers I studied Prolog in university, but only very little. I understand
jsperf's link I'm not a jQuery expert(not even a good user), i haven't studied

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.