D:\NewZebra\JavaApplications\DesignPatternsProject\src\behavior_patterns\command_pattern_w_objects\CoreCommandsPerformer.java
  1 /*
  2  * CoreCommandsPerformer.java
  3  *
  4  * Disclaimer:
  5  * ZebraSoft.com disclaims all warrantees with regard to documents/programs, including 
  6  * all implied warranties. In no event shall ZebraSoft.com be liable for indirect or 
  7  * consequential damages or any damages whatsoever resulting from loss of use, data or 
  8  * profits arising out of the use of documents/programs.
  9  * 
 10  * All content included on this site, such as text, graphics, logos, button icons, 
 11  * images, audio clips, video clips, digital downloads, programs, data compilations, 
 12  * and software, is the property of ZebraSoft.com or its content suppliers and 
 13  * protected by United States and international copyright laws. 
 14  *
 15  * This site or any portion of this site may not be reproduced, duplicated, 
 16  * copied, sold, resold, visited, or otherwise exploited for any commercial 
 17  * purpose without express written consent of ZebraSoft.com.
 18  */
 19 
 20 package behavior_patterns.command_pattern_w_objects;
 21 
 22 /**
 23  *
 24  * @author Sam Eldin
 25  */
 26 
 27 
 28 import java.text.*;
 29 import java.util.*;
 30 import java.awt.event.*;
 31 import java.awt.*;
 32 import javax.swing.*;
 33 
 34 
 35 public class CoreCommandsPerformer extends JFrame implements CommandsPerformer{
 36 
 37     final int                   X_STARTING_POSITION         = 50;
 38     final int                   Y_STARTING_POSITION         = 50;
 39     //=======================================================
 40     int                         local_X_position = X_STARTING_POSITION;
 41     int                         local_Y_position = Y_STARTING_POSITION;
 42     //=======================================================
 43     JButton                     aJButton    = null;
 44     CommandPanel                aCommandPanel = null;
 45     
 46     
 47     /** Creates a new instance of CoreCommandsPerformer */
 48     public CoreCommandsPerformer() {
 49         
 50         setSize(800, 600);
 51         setTitle(" Command Pattern W Objects JFrame");
 52         setLayout(null);
 53         //---------------------------------------
 54         instantiateCommandPanel();
 55         queuingCommands();
 56         runCommands();
 57         //---------------------------------------
 58         setVisible(true);        
 59     }
 60     /**
 61      *
 62      */
 63     public void instantiateCommandPanel(){
 64         aCommandPanel = new CommandPanel();
 65         aCommandPanel.setBounds(0,0,800,600);
 66         aCommandPanel.setBackground(Color.lightGray);
 67         aCommandPanel.setLayout(null);
 68         add(aCommandPanel); 
 69     }
 70     /**
 71      *
 72      */    
 73     public void queuingCommands(){
 74     
 75         if(aCommandPanel != null) {
 76             addButton("Red", 0,  new Command_1());
 77             addButton("Gray", 40, new Command_2());
 78             addButton("Blue", 80, new Command_3());        
 79         }
 80     }
 81     /**
 82      *
 83      */
 84     public void runCommands(){
 85         //no special run is needed in this example
 86     }    
 87     /**
 88      *
 89      */
 90     public void addButton(String buttonName, int verticalPosition,  Command passedCommand){
 91         
 92         if(null == passedCommand)
 93             return;
 94         //===============================================     
 95         final Command localCommand = passedCommand;
 96         local_Y_position += 40 + verticalPosition;
 97         //===============================================     
 98         Cursor handCursor = new Cursor(Cursor.HAND_CURSOR);
 99         //===============================================     
100         aJButton = new JButton(buttonName);
101         aJButton.setCursor(handCursor);
102         aJButton.setBackground(Color.white);
103         aJButton.setBounds(local_X_position, local_Y_position, 100, 20);
104         aCommandPanel.add(aJButton);
105         aJButton.addActionListener(new ActionListener()
106         {
107             public void actionPerformed(ActionEvent PassedActionEvent)
108             {
109                 localCommand.execute(aCommandPanel);
110             }
111         });
112     }   
113     
114     /**
115      *
116      */
117      public static void main (String[] args) {
118          CoreCommandsPerformer coreCommandsPerformerHandle = new CoreCommandsPerformer();
119     }
120     
121 }
122 
123