DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: Point2D ???

  1. #1
    Join Date
    Oct 2004

    Point2D ???

    i have a small program that simply displays a jpg and i want it to draw a "point" when the mouse is first clicked. Then a second point when the mouse is clicked again and then also draws a line between them.

    I will also want to be able to move theses points once they have been painted. What do i use??

    I have been looking at Points2D but i dont understand how to initialze them.

    Points2D p = new Points2D() wont work. I think ideally i will have to enter each mouse click into an array but how do i do that?

  2. #2
    Join Date
    Sep 2004
    You could use the MouseListener interface, it allows you to define the methods:

    mouseClicked(MouseEvent e)
    Invoked when the mouse has been clicked on a component.

    mouseEntered(MouseEvent e)
    Invoked when the mouse enters a component.

    mouseExited(MouseEvent e)
    Invoked when the mouse exits a component.

    mousePressed(MouseEvent e)
    Invoked when a mouse button has been pressed on a component.

    mouseReleased(MouseEvent e)
    Invoked when a mouse button has been released on a component.

    and when the user clicks, call you need to do is to do some coding within the mouseClicked() method.

    What i would do is set a variable when the user clicks it increment it by 1, and simply draw the dot where the mouse clicks (do this by using the event parameter passed into the mouseClicked method "e" and getting the x and y coords) enter the clicked points into a vector and call repaint, then in the paint method go through the array and draw the points.
    The reason i said to have a variable is so that when the user clicks, you check the variable to see if it is even, if it is even then call a method to draw a line between the last 2 entries in the vector.

    As for moving the points, i really cant help ya there...
    A kram a day keeps the doctor......guessing

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
Latest Articles
Questions? Contact us.
Web Development
Latest Tips
Open Source

   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center

We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.