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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T15:25:42+00:00 2026-06-05T15:25:42+00:00

I need to draw a rectange,circle and line and then animate them(press left ->

  • 0

I need to draw a rectange,circle and line and then animate them(press left -> it(all objects) moves left for examp.)

I draw objects like this

class MyCanvas extends JComponent {

int x = 10;
int y = 10;
public MyCanvas()
{
    Action someaction = new AbstractAction(){
        @Override
        public void actionPerformed(ActionEvent e) {
            x+=30;
            //revalidate();
            repaint();
        }
    };
    this.getInputMap().put(KeyStroke.getKeyStroke("SPACE"), someaction);
}        
@Override
public void paintComponent(Graphics g) {
g.drawRect(x,y, 200, 200); 
g.drawOval(x, y, 50, 50);
g.drawLine(x, y, 50, 30);
  }
}

But it doesn’t move.

  • 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-05T15:25:43+00:00Added an answer on June 5, 2026 at 3:25 pm
    1. use paintComponent(Graphics g) for Swing JComponents instead of paint(Graphics g)

    2. use KeyBindings for KeyEvents for Swing JComponents

    3. put Objects (prepare before paintComponent(Graphics g)) to the Array, paint elements from Array in paintComponent(Graphics g)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We are building a web app library which need draw some polyline/polygon/circle/rectange. Also we
I need to draw Line, Circle, and rectangle by mouse drag on canvas and
I need to draw vertical and horizontal rectangle / bands (like in Gantt charts)
I have an application where I need to draw different graphics objects on the
I need draw rectangle with two circle holes inside. The problem is in circles
I need to draw simple alpha maps in xna which depends on current game
I need to draw a chart to show the evolution of data in real
I need to draw a lot of lines. I'm using UIBezierPath for drawing lines
I need to draw 2D overlay over OpenGL scene. OpenGL is used for 2D
A need to draw an X in a View using Shapes , but the

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.