Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 07-02-2007, 06:28 AM
Senior Member
 
Join Date: Jun 2007
Posts: 111
Eric is on a distinguished road
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.

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; }
Thanks.

Eric
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 07-02-2007, 06:34 AM
Senior Member
 
Join Date: Jun 2007
Posts: 114
Albert is on a distinguished road
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
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 07-02-2007, 06:37 AM
Member
 
Join Date: Jun 2007
Posts: 92
Marcus is on a distinguished road
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
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Class explanation mcal New To Java 1 02-05-2008 07:50 PM
need a little explanation cew27 New To Java 7 12-14-2007 12:39 AM
Explanation bout threading and concurrency? cruxblack New To Java 1 08-10-2007 11:33 AM


All times are GMT +3. The time now is 02:03 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org