| Author |
static import of ActionCommands.
|
Timmy Ryan
Ranch Hand
Joined: Dec 09, 2007
Posts: 63
|
|
I have a class that extends JFrame and I want to have another top level class that extends ActionListener to handle the events for this.
Is importing the ActionCommands via a static import the best way to do this?
In JFrame I have
In the ActionListener class I have
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32830
|
|
Timmy Ryan wrote: . . . Is importing the ActionCommands via a static import the best way to do this? . . .
No. Not at all. It is a dreadful way to do it. You want different classes for different actions.
|
 |
Timmy Ryan
Ranch Hand
Joined: Dec 09, 2007
Posts: 63
|
|
Thanks for the response, what way should I split it up?
Currently I have one class that extends JFrame and another that extends ActionListener, to handle the events.
|
 |
Rob Spoor
Sheriff
Joined: Oct 27, 2005
Posts: 19232
|
|
|
A common approach is to give each control gets its own (anonymous) listener.
|
SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
|
 |
Rob Spoor
Sheriff
Joined: Oct 27, 2005
Posts: 19232
|
|
Guru Charan Anand, Your post was moved to a new topic.
|
 |
Timmy Ryan
Ranch Hand
Joined: Dec 09, 2007
Posts: 63
|
|
From reading up a bit more it seems that the Action events are handled in the same class with inner classes. So point taken there.
One final question. Say I have a screen with with a JFrame which contains 3 JPanels.
Would I create this 3 JPanels in the same class as the JFrame(Every example I have looked at has it done this way) or in there own separate classes.
Could you give a reason as to why they are all in the same class?
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32830
|
|
|
You don't need private classes. I have written about this before, here, with links to other useful thread.
|
 |
 |
|
|
subject: static import of ActionCommands.
|
|
|