Results 1 to 3 of 3
  1. #1
    Joe2003 is offline Member
    Join Date
    Jan 2008
    Posts
    21
    Rep Power
    0

    Default JButton onClick?

    Hey

    Im trying to write some simple code that will determine the difference between a mouse click and a mouse unclick. So when the user clicks and holds a button, it would print("hello") untill they released the button.

    is this possible?

    thanks

    Joe

  2. #2
    tim's Avatar
    tim
    tim is offline Senior Member
    Join Date
    Dec 2007
    Posts
    435
    Rep Power
    7

    Default MouseListener

    Hello Joe2003.

    Let your frame or window class implement the MouseListener interface. You will have to implement all the methods of the MouseListener interface. There you will see the mousePressed() and mouseReleased() methods. Add your code there. Remember that you must add the MouseListener to the button, for example:
    Java Code:
    myButton.addMouseListener(this);
    Just ask if you need more detailed help. ;)
    Eyes dwelling into the past are blind to what lies in the future. Step carefully.

  3. #3
    Joe2003 is offline Member
    Join Date
    Jan 2008
    Posts
    21
    Rep Power
    0

Similar Threads

  1. use of onclick function
    By m4tt in forum New To Java
    Replies: 1
    Last Post: 02-16-2008, 03:03 AM
  2. Help with JButton and layout
    By adlb1300 in forum AWT / Swing
    Replies: 1
    Last Post: 12-25-2007, 08:33 AM
  3. How to change TXT color Onclick
    By dave700800 in forum New To Java
    Replies: 1
    Last Post: 12-08-2007, 01:39 AM
  4. Need help with JButton event
    By adlb1300 in forum New To Java
    Replies: 2
    Last Post: 11-19-2007, 01:15 AM
  5. Mouse over JButton
    By sandor in forum AWT / Swing
    Replies: 1
    Last Post: 05-17-2007, 09:15 PM

Posting Permissions

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