java - Nested class vs implements ActionListener -


There are benefits or drawbacks to creating a nested class that implement ActionListener:

  Public square fu {Foo () {something.addActionListener (new button listener ()); } // ... Private class ButtonListener Apply ActionListener {Public Zero Action Action (ActionEvent E) {// ...}}}   

vs. ActionListener applies only to the main category:

  Public Squidoo ActionListener {Foo () {anything.addActionListener (this applies); } // ... Public Zero Effective Action (EVE) {// ...}}   

I have seen both examples often, and just want to know if any 'most' good practice. '

@nankor, you can still use anonymous internal classes as your listeners and are separate free-standing control classes and thus the code is Which is quite stable, I like to use a little bit of technique. For example:

  import java.awt. *; Import java.awt.event. *; Import javax.swing *; Public class benamiinarig {Make private static blank and showwei () {GUIPANEL GUIPANEL = new GUIPANEL (); GuiControl guiControl = New GuiControl (); GuiPanel.setGuiControl (guiControl); GeFreem frame = new Jeffram ("benamiinerge"); Add frame.getContentPane () (guiPanel) .; Frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE); Frame.pack (); Frame.setLocationRelativeTo (zero); Frame.setVisible (true); } Public static zero main (string [] args) {java.awt.EventQueue.invokeLater (new runnab) (public zero run) {createAndShowUI ();}}); }} Class Guipanel JPanel {Private GuiControl control; Public Guipanel () {JButton startButton = new JButton ("Start"); StartButton.addActionListener (New ActionListener) {Public Zero Action Action (ActionEvent e) {if (control! = Null) {control.startButtonActionPerformed (e);}}}); Jebton Endbutton = New Jebton ("End"); EndButton.addActionListener (new executable () {public zero action action (action event e) {if (control! = Tap) {control.endButtonActionPerformed (e);}}}); Adding (startButton); AddButton; } Public Zero Setgie Control (GuiControl Control) {this.control = control; }} Class GuiControl {Public Zero Start Button Action-Operated (Action Avenue) {System.out.println ("Start button pushed"); } Public Zero Ubuntu Action Perfid (Action Avenue) {System.out.println ("End button pushed"); }}    

Comments

Popular posts from this blog

qt - switch/case statement in C++ with a QString type -

python - sqlite3.OperationalError: near "REFERENCES": syntax error - foreign key creating -

Python's equivalent for Ruby's define_method? -