Hello. I have been reading some stuff on the action command pattern. ever heard of it?
More inportantly, Do you understand it?

Because I do not. although I would like to ask if the following
class could use the command pattern as aposed to 'if" or "switch" statements.

I understand the action command pattern uses a interface. I do not understand that either.

is this class a potential canidate to use the action command pattern? if so Could I get
some insight as in how to implement it?
Thanks

NotesAction implements AbstractAction

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package view.menuActions;

import java.awt.event.ActionEvent;
import javax.swing.AbstractAction;
import javax.swing.SwingUtilities;

/**
 *
 * @author Steve's
 */
public class NotesAction extends AbstractAction {

    

    private String name;


    public NotesAction(String name) {
        super();
        

        
    }
   

     public void actionPerformed(ActionEvent e) {

          String M =(" --> in actionPerformed("+e.getActionCommand()+") var: e.getActionCommand() : xxxxxxxx<-- \n");
       System.out.println(M);

            SwingUtilities.invokeLater(new Runnable() {
              public void run() {

                  closeSelectedTab();
              }

            private void closeSelectedTab() {
                 String M =(" --> in closeSelectedTab() var: xxxxxxxxx : xxxxxxxx<-- \n");
                 System.out.println(M);
            }
            });
            SwingUtilities.invokeLater(new Runnable() {
              public void run() {

                  insertSelectedTab();
              }

            private void insertSelectedTab() {
                 String M =(" --> in insertSelectedTab() var: xxxxxxxxx : xxxxxxxx<-- \n");
                 System.out.println(M);
            }
            });
            SwingUtilities.invokeLater(new Runnable() {
              public void run() {

                  deleteSelectedTab();
              }

            private void deleteSelectedTab() {
                 String M =(" --> in deleteSelectedTab() var: xxxxxxxxx : xxxxxxxx<-- \n");
                 System.out.println(M);
            }
            });
            SwingUtilities.invokeLater(new Runnable() {
              public void run() {

                  renameSelectedTab();
              }

            private void renameSelectedTab() {
                 String M =(" --> in renameSelectedTab() var: xxxxxxxxx : xxxxxxxx<-- \n");
                 System.out.println(M);
            }
            });
            SwingUtilities.invokeLater(new Runnable() {
              public void run() {

                 moveOrCopySelectedTab();
              }

            private void moveOrCopySelectedTab() {
                 String M =(" --> in   moveOrCopySelectedTab() var: xxxxxxxxx : xxxxxxxx<-- \n");
                 System.out.println(M);
            }
            });
            SwingUtilities.invokeLater(new Runnable() {
              public void run() {

                  selectAllSheetsSelectedTab();
              }

            private void selectAllSheetsSelectedTab() {
                 String M =(" --> in selectAllSheetsSelectedTab() var: xxxxxxxxx : xxxxxxxx<-- \n");
                 System.out.println(M);
            }
            });
            SwingUtilities.invokeLater(new Runnable() {
              public void run() {

                  targetFoldersSelectedTab();
              }

            private void targetFoldersSelectedTab() {
                 String M =(" --> in targetFoldersSelectedTab() var: xxxxxxxxx : xxxxxxxx<-- \n");
                 System.out.println(M);
            }
            });
           /*
            SwingUtilities.invokeLater(new Runnable() {
              public void run() {

                  closeTab();
              }

            private void closeTab() {
                 String M =(" --> in xxxxxxxxxxxxxxxxx("+xxxxxx+") var: xxxxxxxxx : xxxxxxxx<-- \n");        System.out.println(M);
            }
            });
            * 
            */
             
          }
            
        }

output

What is the profile: admin_
 --> in actionPerformed(insertBtn) var: e.getActionCommand() : xxxxxxxx<-- 

 --> in closeSelectedTab() var: xxxxxxxxx : xxxxxxxx<-- 

 --> in insertSelectedTab() var: xxxxxxxxx : xxxxxxxx<-- 

 --> in deleteSelectedTab() var: xxxxxxxxx : xxxxxxxx<-- 

 --> in renameSelectedTab() var: xxxxxxxxx : xxxxxxxx<-- 

 --> in   moveOrCopySelectedTab() var: xxxxxxxxx : xxxxxxxx<-- 

 --> in selectAllSheetsSelectedTab() var: xxxxxxxxx : xxxxxxxx<-- 

 --> in targetFoldersSelectedTab() var: xxxxxxxxx : xxxxxxxx<--

I guess this is the best thing goin.

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package view.menuActions;

import java.awt.event.ActionEvent;
import javax.swing.AbstractAction;
import javax.swing.JMenuItem;
import javax.swing.SwingUtilities;

/**
 *
 * @author Steve's
 */
public class NotesAction extends AbstractAction implements Runnable {

   
    private String name;
    private JMenuItem tfBtn;

    public NotesAction(String name) {
        super();



    }

    public void actionPerformed(ActionEvent e) {

        String M = (" --> in actionPerformed(" + e.getActionCommand() + ") var: e.getActionCommand() : xxxxxxxx<-- \n");
        System.out.println(M);

        if (e.getActionCommand() == "closeBtn") {
            SwingUtilities.invokeLater(new Runnable() {

                public void run() {

                    closeSelectedTab();
                }

                           });
        }
        if (e.getActionCommand() == "insertBtn") {
            SwingUtilities.invokeLater(new Runnable() {

                public void run() {

                    insertSelectedTab();
                }

                           });
        }
        if (e.getActionCommand() == "deleteBtn") {

            SwingUtilities.invokeLater(new Runnable() {

                public void run() {

                    deleteSelectedTab();
                }

                           });
        }
        if (e.getActionCommand() == "renameBtn") {


            SwingUtilities.invokeLater(new Runnable() {

                public void run() {

                    renameSelectedTab();
                }

                            });
        }
        if (e.getActionCommand() == "mcBtn") {
            SwingUtilities.invokeLater(new Runnable() {

                public void run() {

                    moveOrCopySelectedTab();
                }

                           });
        }
        if (e.getActionCommand() == "sasBtn") {
            SwingUtilities.invokeLater(new Runnable() {

                public void run() {

                    selectAllSheetsSelectedTab();
                }

                           });
        }
        if (e.getActionCommand() == "tfBtn") {
            Thread doMyThread = new Thread(new Runnable() {

                public void run() {

                    targetFoldersSelectedTab();

                }

                
            });
            //SwingUtilities.invokeLater(doMyThread);
            doMyThread.start();

        }



    }

    public void closeSelectedTab() {

        String M = (" --> in actionPerformed() var: e.getActionCommand() : xxxxxxxx<-- \n");
        System.out.println(M);

    }

    public void insertSelectedTab() {

        String M = (" --> in actionPerformed() var: e.getActionCommand() : xxxxxxxx<-- \n");
        System.out.println(M);
    }

    public void deleteSelectedTab() {

        String M = (" --> in actionPerformed() var: e.getActionCommand() : xxxxxxxx<-- \n");
        System.out.println(M);
    }

    public void renameSelectedTab() {

        String M = (" --> in actionPerformed() var: e.getActionCommand() : xxxxxxxx<-- \n");
        System.out.println(M);
    }

    public void moveOrCopySelectedTab() {

        String M = (" --> in actionPerformed() var: e.getActionCommand() : xxxxxxxx<-- \n");
        System.out.println(M);
    }

    public void selectAllSheetsSelectedTab() {

        String M = (" --> in actionPerformed() var: e.getActionCommand() : xxxxxxxx<-- \n");
        System.out.println(M);

    }
    private void targetFoldersSelectedTab() {

                    String M = (" --> in actionPerformed() var: e.getActionCommand() : xxxxxxxx<-- \n");
                    System.out.println(M);
                    System.out.println(key);
                }

    public void run() {
        throw new UnsupportedOperationException("Not supported yet.");
    }
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.