Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

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

 
John Corkrend
Ranch Hand
Posts: 51
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10573
65
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Tony Docherty
Bartender
Posts: 3195
78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 53720
127
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To be pedantic: the name of that class is inappropriate. A class which implements a Listener should be called XXXListener.
 
Tony Docherty
Bartender
Posts: 3195
78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!