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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T21:11:36+00:00 2026-06-05T21:11:36+00:00

This is a long question. I’ve tried to make it more concise but I

  • 0

This is a long question. I’ve tried to make it more concise but I think you need all the info to assist.

Here’s a summary:
I’m trying to capture consecutive clicks as endpoints. I’ll draw line2D objects between these points. I have a listener that sends x and y values from click events to a helper class. I’ll never have more than two points, so the helper class only has firstPoint and secondPoint members. I get the clicks and send the co-ordinates to the helper class using evt.getX() and evt.getY(). The helper creates the points, but firstPoint ends up with the same co-ords as secondPoint. My detail on what’s going on can be found below the code blocks.

Here’s the code in my mouse click handler:

public class Dashboard extends javax.swing.JFrame {

    public static ClickMaster myClicks = new ClickMaster();
    public static boolean drawing = false;
    private MyPoint firstPoint = new MyPoint();
    private MyPoint secondPoint = new MyPoint();

.
.
.

private void MyDrawingPanelMouseClicked(java.awt.event.MouseEvent evt) {
        if (firstPoint.getPointType().equals(MyPoint.PointType.NULL)) {
            drawing = !drawing;
            firstPoint = myClicks.parseClick(evt.getX(), evt.getY(), drawing);
        } else if (drawing){
            drawing = !drawing;
            secondPoint = myClicks.parseClick(evt.getX(), evt.getY(), drawing);
            myClicks.parsePoints(firstPoint, secondPoint);
        }
}

Here’s the helper class that returns points:

public class ClickMaster {

    MyPoint anyPoint = new MyPoint();

    public ClickMaster() {
        anyPoint.setPointType(MyPoint.PointType.NULL);
    }

    public MyPoint parseClick(double x, double y, boolean firstClick) {
            if (firstClick) {
                anyPoint.setPointType(MyPoint.PointType.ANCHOR);
            } else {
                anyPoint.setPointType(MyPoint.PointType.END);
            }

        anyPoint.setX(x);
        anyPoint.setY(y);

        return anyPoint;
    }

And here’s my implementation of Point2D objects, in case it’s relevant:

public class MyPoint extends Point2D {

    public enum PointType {

        ANCHOR, END, SOLO, NULL
    };

    double x;
    double y;
    PointType pointType;

    public MyPoint(PointType pType, double x, double y) {

        this.x = x;
        this.y = y;
        this.pointType = pType;
    }

    public MyPoint() {
        this.x = 0.0;
        this.y = 0.0;
        this.pointType = PointType.NULL;
    }

+ standard getters/setters as you would expect.

debugging shows that

firstPoint = myClicks.parseClick(firstX, firstY, drawing);

results in a point with the x and y values of the mouse event. This is expected.

Likewise,

secondPoint = myClicks.parseClick(evt.getX(), evt.getY(), drawing);

Results in a point with the x and y values of the second click. Also expected.

However, when I call

myClicks.parsePoints(firstPoint, secondPoint);

I see that firstPoint and secondPoint have the same x,y values.

I’m not sure but I believe it’s because both firstPoint and secondPoint are getting their x and y values from the mouse evt. I think I need to put values of type double for x’s and y’s in to firstPoint and secondPoint as opposed to a reference to the double value returned from the mouse event by getX() and getY().

I just don’t know how to make it happen.

Also, if there’s a much better way to capture consecutive clicks and translate them to endpoints for shapes, I would welcome the feedback.

  • 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-05T21:11:37+00:00Added an answer on June 5, 2026 at 9:11 pm

    Actually, your problem is anyPoint. Since you only have one instance of ClickMaster, and anyPoint is only initialized once, you’re returning a reference to the same object no matter how many times you call parseClick. ParseClick needs to create a new MyPoint every time it’s called and return that.

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

Sidebar

Related Questions

This is more like a strategy question: I need to check regularly a long
Sorry for the long question but this contains all the SQL I've used to
Pardon me for this long story, but I think the question merits it. I
I apologize in advance; this is a long question. I've tried to simplify as
Sorry for this long post. The question is however small but requires full detail.
Firstly, This might seem like a long question. I don't think it is... The
JD Long helped me with this: question about manual annotation . But is it
This is probably a long shot but I asked a question about converting one
NOTE: This is a long question. I've explained all the 'basics' at the top
(This looks like a long question, but it's not really, honest!) I am trying

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.