/Users/lyon/j4p/src/addBk/address/AddressHub.java

1    package addBk.address; 
2     
3    import java.awt.event.ActionEvent; 
4    import java.awt.event.ActionListener; 
5     
6    public class AddressHub 
7            implements ActionListener { 
8        AddressBookFrame abf = 
9                new AddressBookFrame(); 
10    
11       CachedDatabase 
12               cd = CachedDatabase.getCachedDatabase(); 
13    
14       int recordNumber = 0; 
15    
16       public void displayIndex() { 
17           IndexFrame indexFrame = 
18                   new IndexFrame(cd); 
19           indexFrame.setVisible(true); 
20       } 
21    
22       public void actionPerformed(ActionEvent e) { 
23           String c = e.getActionCommand(); 
24           if (c.equals("Index")) { 
25               displayIndex(); 
26               return; 
27           } 
28           if (c.equals("Prev")) { 
29               recordNumber--; 
30           } else 
31               recordNumber++; 
32    
33           if (recordNumber >= cd.getSize()) 
34               recordNumber = 0; 
35           if (recordNumber < 0) 
36               recordNumber = cd.getSize() - 1; 
37           abf.setAddress(cd.get(recordNumber)); 
38       } 
39    
40       public void init() { 
41           abf.init(); 
42           cd.init(); 
43           cd.print(); 
44           cd.sort(); 
45           System.out.println("---"); 
46           cd.print(); 
47           abf.setAddress(cd.get(0)); 
48       } 
49    
50       public static void main(String args[]) { 
51           AddressHub h = new AddressHub(); 
52           h.init(); 
53       } 
54   }