Results 1 to 15 of 15
  1. #1
    Michitoshi is offline Member
    Join Date
    Dec 2011
    Posts
    7
    Rep Power
    0

    Default simulating mouseRelease for JLabel

    Hi,

    I have searched quite alot for a solution on my problem, but couldn`t find anything corresponding.
    I would like to let the program simulate a mouseRelease on my JLabel, as the Robot class can do for JButtons. I have tried to use a JButton instead of JLabel and let the JButton look almost like a JLabel, but it`s still not good enough for my program. It must be a JLabel.
    Does someone have any suggestion on how I can make it?
    Last edited by Michitoshi; 12-29-2011 at 07:12 PM.

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,987
    Rep Power
    9

    Default Re: simulating mouseRelease for JLabel

    Why can't you just use the Robot class? Or just call the MouseListener yourself?
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    Michitoshi is offline Member
    Join Date
    Dec 2011
    Posts
    7
    Rep Power
    0

    Default Re: simulating mouseRelease for JLabel

    In the specification of the methods the Robot class does only take int buttons as arguments, so I just assumed that Robot only works for JButton but maybe I have wrong?

    Calling the MouseListener is probably the correct approach, but I don`t really understand how it works with the MouseEvent because I`m supposed to create a new MouseEvent in that case right? Is there any good guidelines for making MouseEvents?

  4. #4
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,987
    Rep Power
    9

    Default Re: simulating mouseRelease for JLabel

    The buttons the Robot API refers to are the mouse buttons (left click, right click, etc), not JButtons. You can click anywhere on the screen, not just on buttons!

    But what exactly are you trying to accomplish? If you don't understand how MouseListeners work, then how are you making anything happen when the user releases the mouse on a JLabel? Can't you simply call the same method from the MouseListener and wherever else?
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  5. #5
    Michitoshi is offline Member
    Join Date
    Dec 2011
    Posts
    7
    Rep Power
    0

    Default Re: simulating mouseRelease for JLabel

    Aha ok, thanks. I`m gonna try the Robot class then.

    No, I managed to make the MouseListener to work, but the arguments for MouseListener methods are MouseEvents and I don`t understand how MouseEvents work.

  6. #6
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,987
    Rep Power
    9

    Default Re: simulating mouseRelease for JLabel

    Quote Originally Posted by Michitoshi View Post
    Aha ok, thanks. I`m gonna try the Robot class then.

    No, I managed to make the MouseListener to work, but the arguments for MouseListener methods are MouseEvents and I don`t understand how MouseEvents work.
    Check out the API then. But I repeat: what exactly are you trying to accomplish? I don't understand why you can't just call the same method from both the MouseListener and wherever in your code you want to repeat the action.
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  7. #7
    Michitoshi is offline Member
    Join Date
    Dec 2011
    Posts
    7
    Rep Power
    0

    Default Re: simulating mouseRelease for JLabel

    Ah, sry. Yes that would be my last solution to just repeat the code anywhere else, since I`m trying to make a bot for the application.

  8. #8
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,419
    Rep Power
    20

    Default Re: simulating mouseRelease for JLabel

    Moved here form 'Advanced Java'.

    And there's nothing 'advanced' about this question, so if you have non-AWT/Swing questions of similar level, please post in the 'New to Java' section.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  9. #9
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,987
    Rep Power
    9

    Default Re: simulating mouseRelease for JLabel

    Quote Originally Posted by Michitoshi View Post
    Ah, sry. Yes that would be my last solution to just repeat the code anywhere else, since I`m trying to make a bot for the application.
    I'm not saying to repeat the code- I'm telling you to collect the code into a method, and then call the method from your "bot" whenever you want. But if you want the mouse to move around and everything, then Robot might be your solution.
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  10. #10
    Michitoshi is offline Member
    Join Date
    Dec 2011
    Posts
    7
    Rep Power
    0

    Default Re: simulating mouseRelease for JLabel

    I appologize for posting at wrong place.

    Yes, you have right, but the Robot seems to be a little bit easier solution in my case. Because I`m using the parameter of MouseEvent in my mouseRelease method.
    Last edited by Michitoshi; 12-30-2011 at 11:35 PM.

  11. #11
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,987
    Rep Power
    9

    Default Re: simulating mouseRelease for JLabel

    Quote Originally Posted by Michitoshi View Post
    I appologize for posting at wrong place.

    Yes, you have right, but the Robot seems to be a little bit easier solution in my case. Because I`m using the parameter of MouseEvent in my mouseRelease method.
    Gotcha. You could still simply construct your own MouseEvent with the desired parameters, but go with whichever way fits into your head the best.
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  12. #12
    Michitoshi is offline Member
    Join Date
    Dec 2011
    Posts
    7
    Rep Power
    0

    Default Re: simulating mouseRelease for JLabel

    Yes, the problem is only that I don`t understand how MouseEvent works. Is there any good guidelines for MouseEvents?

  13. #13
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,987
    Rep Power
    9

    Default Re: simulating mouseRelease for JLabel

    Quote Originally Posted by Michitoshi View Post
    Yes, the problem is only that I don`t understand how MouseEvent works. Is there any good guidelines for MouseEvents?
    The API is your best bet: MouseEvent (Java Platform SE 6)
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  14. #14
    Michitoshi is offline Member
    Join Date
    Dec 2011
    Posts
    7
    Rep Power
    0

    Default Re: simulating mouseRelease for JLabel

    Yes it works well with Robot.

    Thanks, I`ve already seen that page on Oracle, but it`s so hard to understand.

  15. #15
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,562
    Rep Power
    25

    Default Re: simulating mouseRelease for JLabel

    Copy and paste here the parts you don't understand with your questions about what it says.

Similar Threads

  1. Simulating an elevator
    By intrepid604 in forum New To Java
    Replies: 4
    Last Post: 06-05-2011, 10:43 AM
  2. Adding a JLabel to a JPanel - jlabel not showing
    By Bongeh in forum New To Java
    Replies: 17
    Last Post: 04-06-2010, 11:02 PM
  3. java program simulating darts
    By conor147 in forum New To Java
    Replies: 14
    Last Post: 01-18-2010, 02:38 AM
  4. simulating netstat
    By prashant in forum Networking
    Replies: 1
    Last Post: 03-14-2009, 07:41 AM
  5. Simulating Brownian Motion
    By ixhabbaba in forum Java Applets
    Replies: 2
    Last Post: 11-11-2007, 08:53 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
  •