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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T13:13:07+00:00 2026-05-28T13:13:07+00:00

I want to make an application in which I can draw a path on

  • 0

I want to make an application in which I can draw a path on a canvas. The problem is that I have to update this canvas continuously.

Currently I’m able to do it, but I have to redraw all the path every time and so I have to store all the points in memory. I would prefer to simply update the draw by adding a new point.

Is it possible?

Currently my code is:

public class MyCanvas extends Canvas{
        private static final long serialVersionUID = 1L;
        public MyCanvas(){}
        public void paint(Graphics graphics){
            super.paint(graphics);
            graphics.setColor(Color.green);
            // points is an ArrayList of Point2D
            for (Iterator iterator = points.iterator(); iterator.hasNext();) {
               Point2D point2d = (Point2D) iterator.next();
               graphics.fillOval((int)((canvas.getWidth()/2.0) + point2d.getX()), (int)((canvas.getHeight()/2.0) + point2d.getY()), 5, 5);
            }   
        }
    }

Thanks!

EDIT

This is the current solution:

PanelCanvas canvasPanel;
...
public void drawCircle(int x, int y){
    Graphics2D g2d = bufferedImage.createGraphics();
    g2d.setColor(Color.green);
    g2d.setBackground(Color.white);
    g2d.fillOval((int)((panelCanvas.getWidth() / 2.0) + x/10.0), (int)((panelCanvas.getHeight() / 2.0) + y/10.0), 5, 5);
    panelCanvas.repaint();
}

public class CanvasPanel extends JPanel{
    public void paintComponent(Graphics graphics){
        super.paintComponents(graphics);
        Graphics2D g2d = (Graphics2D)graphics;
        g2d.setBackground(Color.white);
        g2d.drawImage(bufferedImage, null, 0, 0);
    }
}
  • 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-05-28T13:13:08+00:00Added an answer on May 28, 2026 at 1:13 pm

    Draw the points (whatever) to a BufferedImage. During paint(), draw the BufferedImage.


    Note though, that the JRE can draw thousands of objects in paint without any visual artifacts or slow-down.


    The canvas is embedded in a Swing GUI. What do you suggest for replacing AWT.Canvas?

    JComponent for complete custom rendering, JPanel for custom rendering combined with components. It sounds like the JComponent would be better suited to this use-case.

    For either of those, override paintComponent(Graphics) instead of paint(Graphics). The rest of the advice is the same.

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

Sidebar

Related Questions

I want to make address book application in android which can have Name,phone No,
I want to make an console application of c which can run other applications
I want to make an application in C or C++ which have to monitor
I have a application written in wxPython which I want to make multilingual. Our
i want to make an application which includes dynamic screensaver. User can select multiple
I want to make an iPhone application through which users can post on their
I want to write an application which can update an twitter status of an
Hey is this possible to make an application which can be used to see
I want to make application in symbian OS mobile which can work in all
So I want to make a java application which, while running, can run custom

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.