Results 1 to 3 of 3
Thread: I need didactic explanation
- 07-02-2007, 05:28 AM #1
Senior Member
- Join Date
- Jun 2007
- Posts
- 111
- Rep Power
- 0
I need didactic explanation
Need a detailed explanation on how this works, I know it does, but not sure how to explain it to some one else.
Thanks.Java Code:public void actionPerformed(ActionEvent event) { int value = 0; if (event.getSource() == tryAgain) guess=0; else if (event.getSource() == one) value = 1; else if (event.getSource() == two) value = 2; else if (event.getSource() == three) value = 3; if(value > 0) { guess *= 10; guess += value; }
Eric
- 07-02-2007, 05:34 AM #2
Senior Member
- Join Date
- Jun 2007
- Posts
- 114
- Rep Power
- 0
Somewhere up in the code there are a few objects (hard to tell what they are from this code) that are named tryAgain, one, two, and three. Something is triggering an event on these that is calling actionPerformed.
I would "guess" that guess is defined as an int somewhere else. It looks like if the event came from tryAgain then you reset the guess. Otherwise you do the math as shown.
Does that make sense?
Greetings.
Albert:rolleyes:
- 07-02-2007, 05:37 AM #3
Member
- Join Date
- Jun 2007
- Posts
- 92
- Rep Power
- 0
Looking at that code, I would assume that the four objects, tryAgain, one, two, and three, all share the same action listener, and this method is the actionPerformed(ActionEvent) method within that class. When an event is triggered, this method is called.
Then, you check four things. First, you check if the object that triggered the event (event.getSource()) is the same object as tryAgain. You perform the same check three more times with different objects.
Note that == compares memory. The code works because when objects are passed into methods the value is not passed in, but a reference of the memory location.
Greetings.
Marcus:cool:
Similar Threads
-
Class explanation
By mcal in forum New To JavaReplies: 1Last Post: 02-05-2008, 06:50 PM -
need a little explanation
By cew27 in forum New To JavaReplies: 7Last Post: 12-13-2007, 11:39 PM -
Explanation bout threading and concurrency?
By cruxblack in forum New To JavaReplies: 1Last Post: 08-10-2007, 10:33 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks