Results 1 to 7 of 7
  1. #1
    j2me64's Avatar
    j2me64 is offline Senior Member
    Join Date
    Sep 2009
    Location
    Zurich, Switzerland
    Posts
    962
    Rep Power
    6

    Default implementing MouseListener

    i'm just implementing a small paint program. for now i'm able to draw a line when the user clicks twice the mouse button. but what i want is drawing points as long the user keeps the mouse button pressed. how can i accomplish that?

  2. #2
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,526
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by j2me64 View Post
    i'm just implementing a small paint program. for now i'm able to draw a line when the user clicks twice the mouse button. but what i want is drawing points as long the user keeps the mouse button pressed. how can i accomplish that?
    Also implement a MouseMotionListener?

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  3. #3
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

  4. #4
    j2me64's Avatar
    j2me64 is offline Senior Member
    Join Date
    Sep 2009
    Location
    Zurich, Switzerland
    Posts
    962
    Rep Power
    6

    Default

    Quote Originally Posted by JosAH View Post
    Also implement a MouseMotionListener?

    kind regards,

    Jos

    clear, but a solution looks like that: inside the mouseClicked() i got the Point from the MouseEvent with getPoint() and the getGraphics() from the canvas, and after setPaint (getPaint() i repaint the canvas with the new Point.

  5. #5
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,526
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by j2me64 View Post
    clear, but a solution looks like that: inside the mouseClicked() i got the Point from the MouseEvent with getPoint() and the getGraphics() from the canvas, and after setPaint (getPaint() i repaint the canvas with the new Point.
    Sounds ok to me but I don't understand your 'but' ... did you read the API documentation for the MouseAdapter class? (Fubarable's suggestion).

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  6. #6
    Jcbconway is offline Senior Member
    Join Date
    Sep 2010
    Posts
    109
    Rep Power
    0

    Default

    Hmm, are you makeing a type of paint program?

  7. #7
    j2me64's Avatar
    j2me64 is offline Senior Member
    Join Date
    Sep 2009
    Location
    Zurich, Switzerland
    Posts
    962
    Rep Power
    6

    Default

    Quote Originally Posted by Jcbconway View Post
    Hmm, are you makeing a type of paint program?

    yes, and here is an example of the output.



    sorry for the calligraphy, but writing with the mouse is not fun. i plan to enhance the app with a menu for changing the paint color and the component (brush, line, rectangle) and so on, something like mspaint in windows.

Similar Threads

  1. can't get x and y from mouselistener
    By j2me64 in forum Java 2D
    Replies: 3
    Last Post: 04-24-2010, 04:57 PM
  2. MouseListener & GUI
    By Suurisa in forum New To Java
    Replies: 2
    Last Post: 10-27-2009, 12:52 AM
  3. Help with Applet implementing mouselistener
    By dsym@comcast.net in forum Java Applets
    Replies: 3
    Last Post: 05-14-2009, 12:57 AM
  4. i need help for MouseListener
    By sfaxianovic in forum New To Java
    Replies: 2
    Last Post: 08-21-2008, 03:30 AM
  5. MouseListener
    By Aswq in forum New To Java
    Replies: 12
    Last Post: 07-18-2008, 08:10 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •