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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T14:48:31+00:00 2026-05-27T14:48:31+00:00

I am creating a Vector Graphics editor and have successfully created the paint-brush and

  • 0

I am creating a Vector Graphics editor and have successfully created the paint-brush and some basic 2d shapes like Rectange, Ellipse , Line etc. Now what’s bothering me is the Curved Line or Curve tool. I created the others by getting the original point from mousePressed and then updating the second point on each mouseDragged. Here’s part of the code:

public void mousePressed(MouseEvent e){
    gfx.setColor(Tool.currentColor);
    pos1 = e.getPoint(); //Get the First Point
}
public void mouseReleased(MouseEvent e){
    if(!e.isAltDown() && !e.isMetaDown())

    if(currentShape != null) shapeSet.add(currentShape);
    currentShape = null;
}
public void mouseDragged(MouseEvent e){
    if(e.isAltDown() || e.isMetaDown()) return;
    //the mouse was dragged, so begin painting
    pos2 = e.getPoint();

    int ctool = Tool.currentTool;

    if(ctool == Tool.LINE){
        currentShape = new Line(pos1,pos2,Tool.currentColor,null);
    }else if(ctool == Tool.ELLIPSE){
        currentShape = new Ellipse(pos1,pos2,Tool.currentColor,null);
    }else if(ctool == Tool.RECTANGLE){
        currentShape = new Rectangle(pos1,pos2,Tool.currentColor,null);
    }

    this.repaint();
}

The Line,Ellipse etc. classes are quite simple, they just take the points and draw them later in the repaint. All the Shapes temporarily stored in currentShape are then later appended to shapeSet , which is an ArrayList of the abstract class Shape.

@Override
public void paintComponent(Graphics g){
    super.paintComponent(g);

    gfx.setBackground(Color.WHITE);

    gfx.clearRect(0, 0, img.getWidth(), img.getHeight());
    for(int i=0; i< shapeSet.size(); i++){
        shapeSet.get(i).draw(gfx);
    }
    if(currentShape != null){
        currentShape.draw(gfx);
    }

    g.drawImage(img, 0, 0, null);
} 

img is a BufferedImage and gfx is img’s Graphics.

img = new BufferedImage(640,480,BufferedImage.TYPE_INT_RGB);
gfx = img.createGraphics(); //Graphics2D

Now how exactly would I go about creating a Curve Tool?

P.S If you want the code of the Shape (Line,Ellipse etc.) classes, just comment and I’ll post it.

  • 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-27T14:48:32+00:00Added an answer on May 27, 2026 at 2:48 pm

    Here’s a Bézier Curve Editor in Java that might give you some ideas, but I’m not sure how you’d integrate it into your program.

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

Sidebar

Related Questions

Ok, so I'm creating a Vector class (the mathematical vector, like [1,3]), and I
I would like to figure out how to save a bitmap or vector graphics
In my data structures course, we are creating a basic vector class. In my
Coming from a C# Background I never used any pointers. I'm creating a vector
Creating a JApplet I have 2 Text Fields, a button and a Text Area.
I am creating a templated Vector class, however, when comparing its use to something
How would you go about creating a vector class in Delphi? I would prefer
Reading about the problem of creating a read only primitive vector in C# (basically,
I am creating a CAD software in which I have a class point &
For a Website I'm developing, I will need to create some graphics. I haven't

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.