Results 1 to 20 of 20
- 12-26-2011, 12:56 AM #1
Member
- Join Date
- Oct 2011
- Posts
- 79
- Rep Power
- 0
- 12-26-2011, 01:10 AM #2
Re: Differentiating user clicks and doClick clicks?
Override the doClick method and catch it there.
- 12-26-2011, 01:16 AM #3
Member
- Join Date
- Oct 2011
- Posts
- 79
- Rep Power
- 0
Re: Differentiating user clicks and doClick clicks?
can you please explain in more details?
- 12-26-2011, 01:20 AM #4
Re: Differentiating user clicks and doClick clicks?
If you override a class's method, then if that method is called, your overriding code will get control.
Extend the JButton class, override the method and add that new class to the GUI. Any calls to the method will be to your code.
- 12-26-2011, 01:24 AM #5
Member
- Join Date
- Oct 2011
- Posts
- 79
- Rep Power
- 0
Re: Differentiating user clicks and doClick clicks?
ok thanks, but I don't think that will help.
I need to know when the user clicks and when the computer clicks on the same button, because sometimes the user clicks need to be ignored.
- 12-26-2011, 01:26 AM #6
Re: Differentiating user clicks and doClick clicks?
How does the computer do the click?
- 12-26-2011, 01:29 AM #7
Member
- Join Date
- Oct 2011
- Posts
- 79
- Rep Power
- 0
Re: Differentiating user clicks and doClick clicks?
Using JButton.doClick() when it is the computer's turn to "play"
- 12-26-2011, 01:30 AM #8
Re: Differentiating user clicks and doClick clicks?
If you override the method then you will know that it was called by the computer.
If it was not called, then the user clicked.
- 12-26-2011, 01:38 AM #9
Member
- Join Date
- Oct 2011
- Posts
- 79
- Rep Power
- 0
Re: Differentiating user clicks and doClick clicks?
I understand what you are saying but I don't know how to code that.
- 12-26-2011, 01:42 AM #10
Re: Differentiating user clicks and doClick clicks?
What part don't you know how to do?
How to extend a class?
How to override a method?
- 12-26-2011, 01:45 AM #11
Member
- Join Date
- Oct 2011
- Posts
- 79
- Rep Power
- 0
Re: Differentiating user clicks and doClick clicks?
im not so sure about neither of those. I'm guessing overriding is done using @Override.
- 12-26-2011, 01:53 AM #12
Re: Differentiating user clicks and doClick clicks?
- 12-26-2011, 01:57 AM #13
Member
- Join Date
- Oct 2011
- Posts
- 79
- Rep Power
- 0
Re: Differentiating user clicks and doClick clicks?
if it is just extends classname then I do know how to extend.
I just got even more confused then before..
- 12-26-2011, 01:59 AM #14
Re: Differentiating user clicks and doClick clicks?
Do you know how to override a method of the class that has been extended?
- 12-26-2011, 02:03 AM #15
Member
- Join Date
- Oct 2011
- Posts
- 79
- Rep Power
- 0
Re: Differentiating user clicks and doClick clicks?
that on the other hand is a no, but i'm trying to understand how it works with your link
from your link, the overrinding is happening here?
Animal myAnimal = myCat;
myAnimal.testInstanceMethod();Last edited by jiffi; 12-26-2011 at 02:05 AM.
- 01-13-2012, 04:33 AM #16
Member
- Join Date
- Oct 2011
- Posts
- 79
- Rep Power
- 0
Re: Differentiating user clicks and doClick clicks?
Ok so I can't make it work, I tried writing public void doClick(), make a new class inside GUI with public void doClick() making one outside etc and none of them seem to work. Please help!!
-
Re: Differentiating user clicks and doClick clicks?
You override by extending a class and override the methods whose behaviors you want to change. For example:
But this is going through a lot of trouble for limited benefit. Why do you even want to do this? And realize doing this will not alter the behavior of any ActionListeners added to the JButton. Your original question has a bad code smell to it.Java Code:class MyButton extends JButton { public MyButton(String title) { super(title); } // plus any other constructors that you want to imitate that of JButton... @Override public void doClick() { System.out.println("software do click!"); super.doClick(); } }
- 01-13-2012, 05:31 AM #18
Member
- Join Date
- Oct 2011
- Posts
- 79
- Rep Power
- 0
Re: Differentiating user clicks and doClick clicks?
Thanks for your answer.
There are some things that I want to happen when the computer clicks that don't when the user clicks. I will try out your solution ASAP.
-
Re: Differentiating user clicks and doClick clicks?
- 01-13-2012, 08:30 AM #20
Member
- Join Date
- Oct 2011
- Posts
- 79
- Rep Power
- 0
Similar Threads
-
How do I check if user clicks on an image?
By rajkobie in forum New To JavaReplies: 10Last Post: 05-04-2011, 04:45 AM -
Responding to clicks outside a window
By bayan in forum New To JavaReplies: 6Last Post: 06-14-2010, 04:51 PM -
The trouble with handling the button clicks
By Borneq in forum New To JavaReplies: 3Last Post: 01-10-2010, 02:57 PM -
How to swap to images on clicks
By ntagrafix in forum AWT / SwingReplies: 2Last Post: 12-03-2009, 08:13 PM -
[SOLVED] Intercepting mouse clicks
By carderne in forum New To JavaReplies: 6Last Post: 02-28-2009, 07:10 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks