/Users/lyon/j4p/src/addBk/addressBook/EditButtonPanel.java

1    package addBk.addressBook; 
2     
3    //EditButtonPanel 
4     
5    import java.awt.*; 
6    import java.awt.event.ActionEvent; 
7    import java.awt.event.ActionListener; 
8     
9     
10   public class EditButtonPanel 
11           extends Panel 
12           implements ActionListener { 
13    
14       RevertButton revertButton 
15               = new RevertButton(); 
16    
17       Button addButton 
18               = new AddButton(); 
19    
20       Button deleteButton 
21               = new DeleteButton(); 
22    
23       public void 
24               actionPerformed(ActionEvent e) { 
25           ((Runnable) 
26                   e.getSource()).run(); 
27       } 
28    
29    
30       EditButtonPanel() { 
31           setLayout( 
32                   new GridLayout(0, 1)); 
33           add(revertButton); 
34           add(addButton); 
35           add(deleteButton); 
36           revertButton.addActionListener(this); 
37           addButton.addActionListener(this); 
38           deleteButton.addActionListener(this); 
39       } 
40    
41       public class RevertButton extends Button 
42               implements Runnable { 
43           RevertButton() { 
44               super("Revert Record"); 
45           } 
46    
47           public void run() { 
48               System.out.println("Run revert"); 
49    
50               AddressBookMediator display = 
51                       new AddressBookMediator(); 
52               if (display.isEditFlag()) 
53                   display.revertRecord(); 
54           } 
55       } 
56    
57       public class AddButton extends Button 
58               implements Runnable { 
59           AddButton() { 
60               super("Add Record"); 
61           } 
62    
63           public void run() { 
64               System.out.println("Run Add"); 
65    
66               AddressBookMediator display = 
67                       new AddressBookMediator(); 
68               if (display.isEditFlag()) 
69                   display.saveCurrentRecord(); 
70    
71               AddressBookRecord abr = 
72                       new AddressBookRecord(); 
73               abr.name = "new record"; 
74               AddressBookMediator.setTextFieldValues(abr); 
75               display.addRecord(); 
76           } 
77       } 
78    
79       public class DeleteButton extends Button 
80               implements Runnable { 
81           DeleteButton() { 
82               super("Delete Record"); 
83           } 
84    
85           public void run() { 
86               System.out.println("Run Delete"); 
87               AddressBookMediator display = 
88                       new AddressBookMediator(); 
89               display.deleteCurrentRecord(); 
90           } 
91       } 
92    
93   } // end class EditButtonPanel 
94