Results 1 to 15 of 15
- 12-29-2011, 07:09 PM #1
Member
- Join Date
- Dec 2011
- Posts
- 7
- Rep Power
- 0
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.
- 12-29-2011, 07:21 PM #2
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!
- 12-29-2011, 07:54 PM #3
Member
- Join Date
- Dec 2011
- Posts
- 7
- Rep Power
- 0
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?
- 12-29-2011, 08:03 PM #4
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!
- 12-29-2011, 08:09 PM #5
Member
- Join Date
- Dec 2011
- Posts
- 7
- Rep Power
- 0
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.
- 12-29-2011, 08:11 PM #6
Re: simulating mouseRelease for JLabel
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-29-2011, 08:20 PM #7
Member
- Join Date
- Dec 2011
- Posts
- 7
- Rep Power
- 0
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.
- 12-29-2011, 10:21 PM #8
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.
dbWhy do they call it rush hour when nothing moves? - Robin Williams
- 12-29-2011, 11:47 PM #9
Re: simulating mouseRelease for JLabel
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-30-2011, 11:28 PM #10
Member
- Join Date
- Dec 2011
- Posts
- 7
- Rep Power
- 0
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.
- 01-02-2012, 05:03 PM #11
Re: simulating mouseRelease for JLabel
How to Ask Questions the Smart Way
Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!
- 01-02-2012, 05:56 PM #12
Member
- Join Date
- Dec 2011
- Posts
- 7
- Rep Power
- 0
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?
- 01-02-2012, 06:59 PM #13
Re: simulating mouseRelease for JLabel
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!
- 01-02-2012, 10:53 PM #14
Member
- Join Date
- Dec 2011
- Posts
- 7
- Rep Power
- 0
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.
- 01-02-2012, 11:20 PM #15
Similar Threads
-
Simulating an elevator
By intrepid604 in forum New To JavaReplies: 4Last Post: 06-05-2011, 10:43 AM -
Adding a JLabel to a JPanel - jlabel not showing
By Bongeh in forum New To JavaReplies: 17Last Post: 04-06-2010, 11:02 PM -
java program simulating darts
By conor147 in forum New To JavaReplies: 14Last Post: 01-18-2010, 02:38 AM -
simulating netstat
By prashant in forum NetworkingReplies: 1Last Post: 03-14-2009, 07:41 AM -
Simulating Brownian Motion
By ixhabbaba in forum Java AppletsReplies: 2Last Post: 11-11-2007, 08:53 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks