Java Swing program question

JetBlack69

Diamond Member
Sep 16, 2001
4,580
1
0
It's creating an anonymous class that implements the ActionListener interface. The class only needs to have one function, actionPerformed. You could create a class and call it ButtonPress and have it implement the ActionListener interface with the actionPerformed method. When you complie the code, you should have VoteDialog.class and VoteDialog$1.class, the $1.class is the anonymous class.
 

AFB

Lifer
Jan 10, 2004
10,718
3
0
Originally posted by: JetBlack69
It's creating an anonymous class that implements the ActionListener interface. The class only needs to have one function, actionPerformed. You could create a class and call it ButtonPress and have it implement the ActionListener interface with the actionPerformed method. When you complie the code, you should have VoteDialog.class and VoteDialog$1.class, the $1.class is the anonymous class.

:thumbsup:

http://java.sun.com/docs/books...vaOO/innerclasses.html
 

kamper

Diamond Member
Mar 18, 2003
5,513
0
0
That's a slightly more advanced java technique which you rarely see used anywhere, except in Swing (although I suspect it is pretty widely used to implement interfaces within the Collections framework)...

If you've ever written guis in a vb style editor this has essentially the same function as a callback. Imho, they way they've used it in that example is very poor coding style because you have a tonne of somewhat unrelated code globbed into one space and most of it doesn't execute linearly. You'd be much better of seperating this out. Either make your ActionListener a seperate class altogether, or make it dumb and just have it call another method of your VoteDialog (that conforms a little better to a VB style callback).

There are other various bad techniques in that code so I'd suggest you don't learn too much from it ;)