This week's book giveaway is in the OCAJP forum.
We're giving away four copies of OCA Java SE 8 Programmer I Study Guide 1Z0-808 and have Jeanne Boyarsky & Scott Selikoff on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Explaining this code(I don't understand it)? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA Java SE 8 Programmer I Study Guide 1Z0-808 this week in the OCAJP forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Explaining this code(I don Watch "Explaining this code(I don New topic
Author

Explaining this code(I don't understand it)?

John Corkrend
Ranch Hand

Joined: Oct 27, 2012
Posts: 51

Here is some of my code that is functional and does what I want it too, but I don't really understand it.



I don't understand this section of the code, the program is a button is on screen(go) and when it is clicked and error message appears but I don't know how.

Please simplify this for me.
Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 8626
    
  23

John Corkrend wrote:I don't understand this section of the code, the program is a button is on screen(go) and when it is clicked and error message appears but I don't know how.

From what you've supplied, it's difficult to say; but if I were to hazard a guess, I'd say that it's part of the code for a generic ActionListener that supplies a default action.

On the other hand, I could be totally out to lunch.

We need more information...and I don't mean a mind-dump; simply the relevant parts that might help to answer this question.

Winston

Isn't it funny how there's always time and money enough to do it WRONG?
Articles by Winston can be found here
Tony Docherty
Bartender

Joined: Aug 07, 2007
Posts: 2522
    
  54
It's because when you click on a JButton it generates an ActionEvent and calls the actionPerformed(ActionEvent e) method on every object that has registered as an ActionListener to that JButton. In your code you register an instance of handleClass as a ActionListener so it's actionPerformed() method is called which displays a JOptionPane dialog with the message "Error".
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 40490
    
  28
To be pedantic: the name of that class is inappropriate. A class which implements a Listener should be called XXXListener.
Tony Docherty
Bartender

Joined: Aug 07, 2007
Posts: 2522
    
  54
Campbell Ritchie wrote:To be pedantic: the name of that class is inappropriate. A class which implements a Listener should be called XXXListener.

Agreed.
It should also start with an upper case letter.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Explaining this code(I don't understand it)?